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



230
231
232
233
234
235
236
237
238
239
240
# File 'lib/asciidoctor/syntax_highlighter.rb', line 230

def format node, lang, opts
  class_attr_val = opts[:nowrap] ? %(#{@pre_class} highlight nowrap) : %(#{@pre_class} highlight)
  if (transform = opts[:transform])
    pre = { 'class' => class_attr_val }
    code = lang ? { 'data-lang' => lang } : {}
    transform[pre, code]
    %(<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