2015-06-28 14:42:41 -04:00
|
|
|
module Rouge
|
|
|
|
module Formatters
|
2016-06-15 15:32:55 -04:00
|
|
|
class HTMLGitlab < Rouge::Formatters::HTML
|
2015-06-28 14:42:41 -04:00
|
|
|
tag 'html_gitlab'
|
|
|
|
|
|
|
|
# Creates a new <tt>Rouge::Formatter::HTMLGitlab</tt> instance.
|
|
|
|
#
|
2016-06-15 15:32:55 -04:00
|
|
|
# [+linenostart+] The line number for the first line (default: 1).
|
|
|
|
def initialize(linenostart: 1)
|
|
|
|
@linenostart = linenostart
|
|
|
|
@line_number = linenostart
|
2015-06-28 14:42:41 -04:00
|
|
|
end
|
|
|
|
|
2016-06-15 15:32:55 -04:00
|
|
|
def stream(tokens, &b)
|
2016-06-21 14:23:10 -04:00
|
|
|
is_first = true
|
2016-06-15 15:32:55 -04:00
|
|
|
token_lines(tokens) do |line|
|
2016-06-21 14:23:10 -04:00
|
|
|
yield "\n" unless is_first
|
|
|
|
is_first = false
|
|
|
|
|
2016-07-15 01:43:49 -04:00
|
|
|
yield %(<span id="LC#{@line_number}" class="line">)
|
2016-07-31 23:51:12 -04:00
|
|
|
line.each { |token, value| yield span(token, value.chomp) }
|
2016-07-15 01:43:49 -04:00
|
|
|
yield %(</span>)
|
2015-06-28 14:42:41 -04:00
|
|
|
|
2016-06-15 15:32:55 -04:00
|
|
|
@line_number += 1
|
2015-06-28 14:42:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|