Class: Asciidoctor::SyntaxHighlighter::Base

Inherits:
Object
  • Object
show all
Includes:
Asciidoctor::SyntaxHighlighter
Defined in:
lib/asciidoctor/syntax_highlighter.rb

Constant Summary

Constants included from DefaultFactory

DefaultFactory::PROVIDED

Instance Attribute Summary

Attributes included from Asciidoctor::SyntaxHighlighter

#name

Instance Method Summary collapse

Methods included from Asciidoctor::SyntaxHighlighter

#docinfo, #docinfo?, #highlight, #highlight?, #initialize, #write_stylesheet, #write_stylesheet?

Methods included from DefaultFactory

#for, #register

Methods included from Factory

#create, #for, #register

Instance Method Details

#format(node, lang, opts) ⇒ Object



233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/asciidoctor/syntax_highlighter.rb', line 233

def format node, lang, opts
  class_attr_val = opts[:nowrap] ? %(#{@pre_class} highlight nowrap) : %(#{@pre_class} highlight)
  if (transform = opts[:transform])
    transform[(pre = { 'class' => class_attr_val }), (code = lang ? { 'data-lang' => lang } : {})]
    # NOTE: make sure data-lang is the last attribute on the code tag to remain consistent with 1.5.x
    if (lang = code.delete 'data-lang')
      code['data-lang'] = lang
    end
    %(<pre#{pre.map {|k, v| %[ #{k}="#{v}"] }.join}><code#{code.map {|k, v| %[ #{k}="#{v}"] }.join}>#{node.content}</code></pre>)
  else
    %(<pre class="#{class_attr_val}"><code#{lang ? %[ data-lang="#{lang}"] : ''}>#{node.content}</code></pre>)
  end
end