lib/maruku/to_html.rb in maruku-0.2.7 vs lib/maruku/to_html.rb in maruku-0.2.8
- old
+ new
@@ -251,47 +251,57 @@
lang = 'xml' if lang=='html'
use_syntax = @doc.meta[:html_use_syntax]
element =
if use_syntax && lang
- convertor = Syntax::Convertors::HTML.for_syntax lang
- html = convertor.convert( source )
+ begin
+ convertor = Syntax::Convertors::HTML.for_syntax lang
+ html = convertor.convert( source )
- show_spaces = get_setting(:code_show_spaces)
- if show_spaces
- s.gsub!(/\t/,'»'+' '*3)
- s.gsub!(/ /,'¬')
- end
+ show_spaces = get_setting(:code_show_spaces)
+ if show_spaces
+ s.gsub!(/\t/,'»'+' '*3)
+ s.gsub!(/ /,'¬')
+ end
-# puts "html: #{html}"
- pre = Document.new(html, {:respect_whitespace =>:all}).root
- pre.attributes['class'] = lang
-# puts "After: #{pre}"
- pre
- else
- pre = Element.new 'pre'
- s = source
-
- s = s.gsub(/&/,'&')
- s = Text.normalize(s)
-
- show_spaces = get_setting(:code_show_spaces)
- if show_spaces
- s.gsub!(/\t/,'»'+' '*3)
- s.gsub!(/ /,'¬')
+ pre = Document.new(html, {:respect_whitespace =>:all}).root
+ pre.attributes['class'] = lang
+ pre
+ rescue Object => e
+ $stderr.puts "Error while using the syntax library for code:\n#{source.inspect}"
+ $stderr.puts "Lang is #{lang} object is: "
+ $stderr.puts @meta.inspect
+ $stderr.puts "Exception: #{e.class}: #{e.message}\n\t#{e.backtrace.join("\n\t")}"
+ to_html_code_using_pre(source)
end
-
- text = Text.new(s, true, nil, false )
-
- pre << text
- pre
+ else
+ to_html_code_using_pre(source)
end
color = get_setting(:code_background_color,DEFAULT_CODE_COLOR)
if color
element.attributes['style'] = "background-color: #{color};"
end
element
+ end
+
+ def to_html_code_using_pre(source)
+ pre = Element.new 'pre'
+ s = source
+
+ s = s.gsub(/&/,'&')
+ s = Text.normalize(s)
+
+ show_spaces = get_setting(:code_show_spaces)
+ if show_spaces
+ s.gsub!(/\t/,'»'+' '*3)
+ s.gsub!(/ /,'¬')
+ end
+
+ text = Text.new(s, true, nil, false )
+
+ pre << text
+ pre
end
def to_html_inline_code;
pre = Element.new 'tt'
source = self.meta[:raw_code]