class Asciidoctor::Html5s::HtmlPipelineHighlighter

Modification of Asciidoctor::SyntaxHighlighter::HtmlPipelineAdapter that uses attribute `data-lang` instead of `lang`.

Rationale: Attribute `lang` is defined for natural language of text, not for programming languages.

Public Class Methods

new(name, backend, opts = {}) click to toggle source
Calls superclass method
# File lib/asciidoctor/html5s/html_pipeline_highlighter.rb, line 13
def initialize(name, backend, opts = {})
  super
  # Use this version of the #format method only for our backend, otherwise
  # use the original variant.
  singleton_class.send(:alias_method, :format, :format_orig) if backend != 'html5s'
end

Public Instance Methods

format(node, lang, _opts) click to toggle source
# File lib/asciidoctor/html5s/html_pipeline_highlighter.rb, line 20
def format(node, lang, _opts)
  %(<pre><code#{%{ data-lang="#{lang}"} if lang}>#{node.content}</code></pre>)
end
format_orig(node, lang, _opts) click to toggle source

Copied from Asciidoctor::SyntaxHighlighter::HtmlPipelineAdapter#format. Note: HtmlPipelineAdapter is not available in asciidoctor.js, that's why it's done like this instead of delegation or inheritance.

# File lib/asciidoctor/html5s/html_pipeline_highlighter.rb, line 27
def format_orig(node, lang, _opts)
  %(<pre#{%{ lang="#{lang}"} if lang}><code>#{node.content}</code></pre>)
end