class Stepmod::Utils::Converters::Text
Public Instance Methods
convert(node, state = {})
click to toggle source
# File lib/stepmod/utils/converters/text.rb, line 7 def convert(node, state = {}) if node.text.strip.empty? treat_empty(node, state) else treat_text(node) end end
Private Instance Methods
preserve_keychars_within_backticks(text)
click to toggle source
# File lib/stepmod/utils/converters/text.rb, line 56 def preserve_keychars_within_backticks(text) text.gsub(/`.*?`/) do |match| match.gsub('\_', "_").gsub('\*', "*") end end
preserve_nbsp(text)
click to toggle source
# File lib/stepmod/utils/converters/text.rb, line 40 def preserve_nbsp(text) text.gsub(/\u00A0/, " ") end
remove_border_newlines(text)
click to toggle source
# File lib/stepmod/utils/converters/text.rb, line 48 def remove_border_newlines(text) text.gsub(/\A\n+/, "").gsub(/\n+\z/, "") end
remove_inner_newlines(text)
click to toggle source
# File lib/stepmod/utils/converters/text.rb, line 52 def remove_inner_newlines(text) text.tr("\n\t", " ").squeeze(" ") end
treat_empty(node, state)
click to toggle source
# File lib/stepmod/utils/converters/text.rb, line 17 def treat_empty(node, state) parent = node.parent.name.to_sym if %i[ol ul].include?(parent) # Otherwise the identation is broken "" elsif state[:tdsinglepara] "" elsif node.text == " " # Regular whitespace text node " " else "" end end
treat_text(node)
click to toggle source
# File lib/stepmod/utils/converters/text.rb, line 30 def treat_text(node) text = node.text text = preserve_nbsp(text) text = remove_inner_newlines(text) text = remove_border_newlines(text) text = preserve_keychars_within_backticks(text) preserve_tags(text) end