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.
|
|
|
|
#
|
2017-03-13 14:17:07 -04:00
|
|
|
# [+tag+] The tag (language) of the lexer used to generate the formatted tokens
|
|
|
|
def initialize(tag: nil)
|
|
|
|
@line_number = 1
|
2017-03-10 16:34:29 -05:00
|
|
|
@tag = tag
|
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
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
yield %(<span id="LC#{@line_number}" class="line" lang="#{@tag}">)
|
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
|