Class: RTF::Converters::HTML::Node
- Inherits:
-
Object
- Object
- RTF::Converters::HTML::Node
- Defined in:
- lib/rtf/converters/html.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(node) ⇒ Node
constructor
A new instance of Node.
- #recurse ⇒ Object
- #to_rtf(rtf) ⇒ Object
Constructor Details
#initialize(node) ⇒ Node
Returns a new instance of Node.
89 90 91 |
# File 'lib/rtf/converters/html.rb', line 89 def initialize(node) @node = node end |
Instance Method Details
#recurse ⇒ Object
117 118 119 |
# File 'lib/rtf/converters/html.rb', line 117 def recurse lambda {|rtf| NodeSet.new(@node.children).to_rtf(rtf)} end |
#to_rtf(rtf) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/rtf/converters/html.rb', line 93 def to_rtf(rtf) case @node.name when 'text' then rtf << @node.text.gsub(/\n+/, ' ').strip when 'br' then rtf.line_break when 'b', 'strong' then rtf.bold &recurse when 'i', 'em', 'cite' then rtf.italic &recurse when 'u' then rtf.underline &recurse when 'blockquote', 'p', 'div' then rtf.paragraph &recurse when 'span' then recurse.call(rtf) when 'sup' then rtf.subscript &recurse when 'sub' then rtf.superscript &recurse when 'ul' then rtf.list :bullets, &recurse when 'ol' then rtf.list :decimal, &recurse when 'li' then rtf.item &recurse when 'a' then rtf.link @node[:href], &recurse when 'h1', 'h2', 'h3', 'h4' then rtf.apply(Helpers.style(@node.name), &recurse); rtf.line_break when 'code' then rtf.font Helpers.font(:monospace), &recurse else #puts "Ignoring #{@node.to_html}" end return rtf end |