Class: Asciidoctor::Rouge::HtmlFormatter
- Inherits:
-
Rouge::Formatter
- Object
- Rouge::Formatter
- Asciidoctor::Rouge::HtmlFormatter
- Defined in:
- lib/asciidoctor/rouge/html_formatter.rb
Overview
An HTML Rouge formatter for Asciidoctor with support for callouts and highlighted lines.
Instance Method Summary collapse
-
#initialize(callout_markers: nil, highlighted_class: 'highlighted', highlighted_lines: [], inline_theme: nil, line_class: 'line', line_id: 'L%i', inner: nil) ⇒ HtmlFormatter
constructor
A new instance of HtmlFormatter.
- #stream(tokens, &block) ⇒ void
-
#stream_lines(tokens, line_num) {|String| ... } ⇒ void
Formats tokens on the specified line into HTML.
Constructor Details
#initialize(callout_markers: nil, highlighted_class: 'highlighted', highlighted_lines: [], inline_theme: nil, line_class: 'line', line_id: 'L%i', inner: nil) ⇒ HtmlFormatter
Returns a new instance of HtmlFormatter.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/asciidoctor/rouge/html_formatter.rb', line 38 def initialize(callout_markers: nil, highlighted_class: 'highlighted', highlighted_lines: [], inline_theme: nil, line_class: 'line', line_id: 'L%i', inner: nil, **) inner ||= if inline_theme ::Rouge::Formatter.find('html_inline').new(inline_theme) else ::Rouge::Formatter.find('html').new end @callout_markers = callout_markers || {} @inner = inner @highlighted_lines = highlighted_lines || [] @highlighted_class = highlighted_class @line_id = line_id @line_class = line_class end |
Instance Method Details
#stream(tokens, &block) ⇒ void
60 61 62 63 64 |
# File 'lib/asciidoctor/rouge/html_formatter.rb', line 60 def stream(tokens, &block) token_lines(tokens).with_index(1) do |line_tokens, lno| stream_lines(line_tokens, lno, &block) end end |
#stream_lines(tokens, line_num) {|String| ... } ⇒ void
Formats tokens on the specified line into HTML.
71 72 73 74 75 76 77 78 79 |
# File 'lib/asciidoctor/rouge/html_formatter.rb', line 71 def stream_lines(tokens, line_num) yield line_start(line_num) tokens.each do |token, value| yield @inner.span(token, value) end yield line_end(line_num) end |