lib/rouge/formatters/html.rb in rouge-0.3.6 vs lib/rouge/formatters/html.rb in rouge-0.3.7
- old
+ new
@@ -10,10 +10,11 @@
# @option opts :css_class
# A css class to be used for the generated <pre> tag.
def initialize(opts={})
@css_class = opts[:css_class] || 'highlight'
@line_numbers = opts.fetch(:line_numbers) { false }
+ @wrap = opts.fetch(:wrap, true)
end
# @yield the html output.
def stream(tokens, &b)
if @line_numbers
@@ -22,15 +23,15 @@
stream_untableized(tokens, &b)
end
end
def stream_untableized(tokens, &b)
- yield "<pre class=#{@css_class.inspect}>"
+ yield "<pre class=#{@css_class.inspect}>" if @wrap
tokens.each do |tok, val|
span(tok, val, &b)
end
- yield '</pre>'
+ yield '</pre>' if @wrap
end
def stream_tableized(tokens, &b)
num_lines = 0
code = ''
@@ -46,11 +47,11 @@
# generate a string of newline-separated line numbers for the gutter
numbers = num_lines.times.map do |x|
%<<div class="lineno">#{x+1}</div>>
end.join
- yield "<pre class=#{@css_class.inspect}>"
+ yield "<pre class=#{@css_class.inspect}>" if @wrap
yield "<table><tbody><tr>"
# the "gl" class applies the style for Generic.Lineno
yield '<td class="gutter gl">'
yield numbers
@@ -59,10 +60,10 @@
yield '<td class="code">'
yield code
yield '</td>'
yield '</tr></tbody></table>'
- yield '</pre>'
+ yield '</pre>' if @wrap
end
private
def span(tok, val, &b)
# TODO: properly html-encode val