Class: Nokogiri::XML::Node
- Inherits:
-
Object
- Object
- Nokogiri::XML::Node
- Defined in:
- lib/html2fortitude/html.rb
Overview
Instance Attribute Summary collapse
-
#converted_to_fortitude ⇒ Boolean
Whether this node has already been converted to Fortitude.
Instance Method Summary collapse
-
#to_fortitude(tabs, options) ⇒ Object
Returns the Fortitude representation of the given node.
Instance Attribute Details
#converted_to_fortitude ⇒ Boolean
Whether this node has already been converted to Fortitude. Only used for text nodes and elements.
19 20 21 |
# File 'lib/html2fortitude/html.rb', line 19 def converted_to_fortitude @converted_to_fortitude end |
Instance Method Details
#to_fortitude(tabs, options) ⇒ Object
Returns the Fortitude representation of the given node.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/html2fortitude/html.rb', line 25 def to_fortitude(tabs, ) return "" if converted_to_fortitude # Eliminate whitespace that has no newlines as_string = self.to_s return "" if as_string.strip.empty? && as_string !~ /[\r\n]/mi if as_string.strip.empty? # If we get here, it's whitespace, but containing newlines; eliminate trailing indentation as_string = $1 if as_string =~ /^(.*?[\r\n])[ \t]+$/mi return as_string end # We have actual content if we get here; deal with leading and trailing newline/whitespace combinations properly text = uninterp(as_string) if text =~ /\A((?:\s*[\r\n])*)(.*?)((?:\s*[\r\n])*)\Z/mi prefix, middle, suffix = $1, $2, $3 middle = parse_text_with_interpolation(middle, tabs) return prefix + middle + suffix else return parse_text_with_interpolation(text, tabs) end end |