A simple class for converting a text into HTML.
Methods
Public Instance methods
Converts the given text to HTML, using spans to represent token groups of any type but :normal (which is always unhighlighted). If pre is true, the html is automatically wrapped in pre tags.
[ show source ]
# File lib/syntax/convertors/html.rb, line 12
12: def convert( text, pre=true )
13: html = ""
14: html << "<pre>" if pre
15: regions = []
16: @tokenizer.tokenize( text ) do |tok|
17: value = html_escape(tok)
18: case tok.instruction
19: when :region_close then
20: regions.pop
21: html << "</span>"
22: when :region_open then
23: regions.push tok.group
24: html << "<span class=\"#{tok.group}\">#{value}"
25: else
26: if tok.group == ( regions.last || :normal )
27: html << value
28: else
29: html << "<span class=\"#{tok.group}\">#{value}</span>"
30: end
31: end
32: end
33: html << "</span>" while regions.pop
34: html << "</pre>" if pre
35: html
36: end