gitlab-org--gitlab-foss/lib/rouge/formatters/html_gitlab.rb
gfyoung c8755543f0 Enable even more frozen string in lib/**/*.rb
Enables frozen string for the following files:

* lib/generators/**/*.rb
* lib/gitaly/**/*.rb
* lib/google_api/**/*.rb
* lib/haml_lint/**/*.rb
* lib/json_web_token/**/*.rb
* lib/mattermost/**/*.rb
* lib/microsoft_teams/**/*.rb
* lib/object_storage/**/*.rb
* lib/omni_auth/**/*.rb
* lib/peek/**/*.rb
* lib/rouge/**/*.rb
* lib/rspec_flaky/**/*.rb
* lib/system_check/**/*.rb

Partially addresses #47424.
2018-10-08 11:16:49 -07:00

31 lines
785 B
Ruby

# frozen_string_literal: true
module Rouge
module Formatters
class HTMLGitlab < Rouge::Formatters::HTML
tag 'html_gitlab'
# Creates a new <tt>Rouge::Formatter::HTMLGitlab</tt> instance.
#
# [+tag+] The tag (language) of the lexer used to generate the formatted tokens
def initialize(tag: nil)
@line_number = 1
@tag = tag
end
def stream(tokens)
is_first = true
token_lines(tokens) do |line|
yield "\n" unless is_first
is_first = false
yield %(<span id="LC#{@line_number}" class="line" lang="#{@tag}">)
line.each { |token, value| yield span(token, value.chomp) }
yield %(</span>)
@line_number += 1
end
end
end
end
end