Class: Prosereflect::Output::Html
- Inherits:
-
Object
- Object
- Prosereflect::Output::Html
- Defined in:
- lib/prosereflect/output/html.rb
Class Method Summary collapse
-
.convert(document) ⇒ Object
Convert a Prosereflect::Document to HTML.
Class Method Details
.convert(document) ⇒ Object
Convert a Prosereflect::Document to HTML
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/prosereflect/output/html.rb', line 11 def convert(document) builder = Nokogiri::HTML::Builder.new do |doc| doc.div do process_node(document, doc) end end doc = Nokogiri::HTML(builder.to_html) html = doc.at_css('div').children.to_html code_blocks = {} html.scan(%r{<code[^>]*>(.*?)</code>}m).each_with_index do |match, i| code_content = match[0] placeholder = "CODE_BLOCK_#{i}" code_blocks[placeholder] = code_content html.sub!(code_content, placeholder) end # Remove newlines and spaces html = html.gsub(/\n\s*/, '') code_blocks.each do |placeholder, content| html.sub!(placeholder, content) end html end |