Class: Rouge::Formatters::HTMLGitlab

Inherits:
HTML
  • Object
show all
Defined in:
lib/rouge/formatters/html_gitlab.rb

Instance Method Summary collapse

Constructor Details

#initialize(tag: nil) ⇒ HTMLGitlab

Creates a new Rouge::Formatter::HTMLGitlab instance.

tag

The tag (language) of the lexer used to generate the formatted tokens


11
12
13
14
# File 'lib/rouge/formatters/html_gitlab.rb', line 11

def initialize(tag: nil)
  @line_number = 1
  @tag = tag
end

Instance Method Details

#stream(tokens) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rouge/formatters/html_gitlab.rb', line 16

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