A simple class for converting a text into HTML.
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.
# 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
Replaces some characters with their corresponding HTML entities.
# File lib/syntax/convertors/html.rb, line 41 41: def html_escape( string ) 42: string.gsub( /&/, "&" ). 43: gsub( /</, "<" ). 44: gsub( />/, ">" ). 45: gsub( /"/, """ ) 46: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.