Class: Rouge::Formatters::HTMLGitlab

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

Instance Method Summary collapse

Constructor Details

#initialize(nowrap: false, cssclass: 'highlight', linenos: nil, linenostart: 1, lineanchors: false, lineanchorsid: 'L', anchorlinenos: false, inline_theme: nil) ⇒ HTMLGitlab

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

nowrap

If set to True, don't wrap the output at all, not even inside a <pre> tag (default: false).

cssclass

CSS class for the wrapping <div> tag (default: 'highlight').

linenos

If set to 'table', output line numbers as a table with two cells, one containing the line numbers, the other the whole code. This is copy paste friendly, but may cause alignment problems with some browsers or fonts. If set to 'inline', the line numbers will be integrated in the <pre> tag that contains the code (default: nil).

linenostart

The line number for the first line (default: 1).

lineanchors

If set to true the formatter will wrap each output line in an anchor tag with a name of L-linenumber. This allows easy linking to certain lines (default: false).

lineanchorsid

If lineanchors is true the name of the anchors can be changed with lineanchorsid to e.g. foo-linenumber (default: 'L').

anchorlinenos

If set to true, will wrap line numbers in <a> tags. Used in combination with linenos and lineanchors (default: false).

inline_theme

Inline CSS styles for the <pre> tag (default: false).


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rouge/formatters/html_gitlab.rb', line 33

def initialize(
    nowrap: false,
    cssclass: 'highlight',
    linenos: nil,
    linenostart: 1,
    lineanchors: false,
    lineanchorsid: 'L',
    anchorlinenos: false,
    inline_theme: nil
)
  @nowrap = nowrap
  @cssclass = cssclass
  @linenos = linenos
  @linenostart = linenostart
  @lineanchors = lineanchors
  @lineanchorsid = lineanchorsid
  @anchorlinenos = anchorlinenos
  @inline_theme = Theme.find(inline_theme).new if inline_theme.is_a?(String)
end

Instance Method Details

#render(tokens) ⇒ Object Also known as: format


53
54
55
56
57
58
59
60
61
62
# File 'lib/rouge/formatters/html_gitlab.rb', line 53

def render(tokens)
  case @linenos
  when 'table'
    render_tableized(tokens)
  when 'inline'
    render_untableized(tokens)
  else
    render_untableized(tokens)
  end
end