debian-mirror-gitlab/lib/rouge/formatters/html_gitlab.rb

30 lines
762 B
Ruby
Raw Normal View History

2015-09-11 14:41:01 +05:30
module Rouge
module Formatters
2016-08-24 12:49:21 +05:30
class HTMLGitlab < Rouge::Formatters::HTML
2015-09-11 14:41:01 +05:30
tag 'html_gitlab'
# Creates a new <tt>Rouge::Formatter::HTMLGitlab</tt> instance.
#
# [+linenostart+] The line number for the first line (default: 1).
2016-08-24 12:49:21 +05:30
def initialize(linenostart: 1)
2015-09-11 14:41:01 +05:30
@linenostart = linenostart
2016-08-24 12:49:21 +05:30
@line_number = linenostart
2015-09-11 14:41:01 +05:30
end
2016-08-24 12:49:21 +05:30
def stream(tokens, &b)
is_first = true
token_lines(tokens) do |line|
yield "\n" unless is_first
is_first = false
2015-09-11 14:41:01 +05:30
2016-08-24 12:49:21 +05:30
yield %(<span id="LC#{@line_number}" class="line">)
line.each { |token, value| yield span(token, value.chomp) }
yield %(</span>)
2015-09-11 14:41:01 +05:30
2016-08-24 12:49:21 +05:30
@line_number += 1
2015-09-11 14:41:01 +05:30
end
end
end
end
end