Class: Asciidoctor::Html5s::HtmlPipelineHighlighter
- Inherits:
-
SyntaxHighlighter::Base
- Object
- SyntaxHighlighter::Base
- Asciidoctor::Html5s::HtmlPipelineHighlighter
- Defined in:
- lib/asciidoctor/html5s/html_pipeline_highlighter.rb
Overview
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.
Instance Method Summary collapse
- #format(node, lang, _opts) ⇒ Object
-
#format_orig(node, lang, _opts) ⇒ Object
Copied from Asciidoctor::SyntaxHighlighter::HtmlPipelineAdapter#format.
-
#initialize(name, backend, opts = {}) ⇒ HtmlPipelineHighlighter
constructor
A new instance of HtmlPipelineHighlighter.
Constructor Details
#initialize(name, backend, opts = {}) ⇒ HtmlPipelineHighlighter
Returns a new instance of HtmlPipelineHighlighter.
13 14 15 16 17 18 |
# 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 |
Instance Method Details
#format(node, lang, _opts) ⇒ Object
20 21 22 |
# 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) ⇒ Object
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.
27 28 29 |
# 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 |