Method: Tree.to_html

Defined in:
lib/xiki/tree.rb

.to_html(txt) ⇒ Object

Tree.to_html “p/n hin”



1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
# File 'lib/xiki/tree.rb', line 1766

def self.to_html txt
  html = ""

  txt = txt.gsub /^( *)([+-] )?(\w[\w ]*\/)(.+)/, "\\1\\3\n\\1  \\4"   # Preprocess to break foo/Bar into separate lines

  previous = []
  Tree.traverse(txt) do |l, path|

    last = l.last
    next if !last   # Blank lines

    self.add_closing_tags html, l, previous   # If lower than last, add any closing tags

    last = Line.without_label :line=>last
    if last =~ /([^*\n]+)\/$/
      tag = $1
      html.<<("  " * (l.length-1)) unless l[-2] =~ /[ +-]*pre\/$/

      next html << "<#{tag}>\n"
    end

    last.sub! /^\| ?/, ''

    if last =~ /\.\.\.$/   # If "Lorem..." or "Lorem ipsum..." etc. make progressively longer
      old_length = last.length
      last.gsub!(/\w+/){|o| @@lorem[o.downcase] || o}
      last.sub!(/\.\.\.$/, '') if last.length != old_length   # Remove ... if we replaced something
    end

    parent = l[-2]
    html.<<("  " * (l.length-1)) unless parent =~ /[ +-]*pre\/$/

    html << "#{last}\n"
  end


  self.add_closing_tags html, [], previous

  html
end