2015-06-28 18:42:41 +00:00
|
|
|
module Rouge
|
|
|
|
module Formatters
|
2016-06-15 19:32:55 +00:00
|
|
|
class HTMLGitlab < Rouge::Formatters::HTML
|
2015-06-28 18:42:41 +00:00
|
|
|
tag 'html_gitlab'
|
|
|
|
|
|
|
|
# Creates a new <tt>Rouge::Formatter::HTMLGitlab</tt> instance.
|
|
|
|
#
|
2017-03-13 18:17:07 +00:00
|
|
|
# [+tag+] The tag (language) of the lexer used to generate the formatted tokens
|
|
|
|
def initialize(tag: nil)
|
|
|
|
@line_number = 1
|
2017-03-10 21:34:29 +00:00
|
|
|
@tag = tag
|
2015-06-28 18:42:41 +00:00
|
|
|
end
|
|
|
|
|
2016-06-15 19:32:55 +00:00
|
|
|
def stream(tokens, &b)
|
2016-06-21 18:23:10 +00:00
|
|
|
is_first = true
|
2016-06-15 19:32:55 +00:00
|
|
|
token_lines(tokens) do |line|
|
2016-06-21 18:23:10 +00:00
|
|
|
yield "\n" unless is_first
|
|
|
|
is_first = false
|
|
|
|
|
2017-03-10 21:34:29 +00:00
|
|
|
yield %(<span id="LC#{@line_number}" class="line" lang="#{@tag}">)
|
2016-08-01 03:51:12 +00:00
|
|
|
line.each { |token, value| yield span(token, value.chomp) }
|
2016-07-15 05:43:49 +00:00
|
|
|
yield %(</span>)
|
2015-06-28 18:42:41 +00:00
|
|
|
|
2016-06-15 19:32:55 +00:00
|
|
|
@line_number += 1
|
2015-06-28 18:42:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|