Class: Asciidoctor::SyntaxHighlighter::HighlightJsAdapter

Inherits:
Base
  • Object
show all
Defined in:
lib/asciidoctor/syntax_highlighter/highlightjs.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

#highlight, #highlight?, #write_stylesheet, #write_stylesheet?

Methods included from DefaultFactory

#for, #register

Methods included from Factory

#create, #for, #register

Constructor Details

#initialize(*args) ⇒ HighlightJsAdapter

Returns a new instance of HighlightJsAdapter.



6
7
8
9
# File 'lib/asciidoctor/syntax_highlighter/highlightjs.rb', line 6

def initialize *args
  super
  @name = @pre_class = 'highlightjs'
end

Instance Method Details

#docinfo(location, doc, opts) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/asciidoctor/syntax_highlighter/highlightjs.rb', line 19

def docinfo location, doc, opts
  base_url = doc.attr 'highlightjsdir', %(#{opts[:cdn_base_url]}/highlight.js/#{HIGHLIGHT_JS_VERSION})
  if location == :head
    %(<link rel="stylesheet" href="#{base_url}/styles/#{doc.attr 'highlightjs-theme', 'github'}.min.css"#{opts[:self_closing_tag_slash]}>)
  else # :footer
    %(<script src="#{base_url}/highlight.min.js"></script>
#{(doc.attr? 'highlightjs-languages') ? ((doc.attr 'highlightjs-languages').split ',').map {|lang| %[<script src="#{base_url}/languages/#{lang.lstrip}.min.js"></script>\n] }.join : ''}<script>
if (!hljs.initHighlighting.called) {
hljs.initHighlighting.called = true
;[].slice.call(document.querySelectorAll('pre.highlight > code')).forEach(function (el) { hljs.highlightBlock(el) })
}
</script>)
  end
end

#docinfo?(location) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/asciidoctor/syntax_highlighter/highlightjs.rb', line 15

def docinfo? location
  true
end

#format(node, lang, opts) ⇒ Object



11
12
13
# File 'lib/asciidoctor/syntax_highlighter/highlightjs.rb', line 11

def format node, lang, opts
  super node, lang, (opts.merge transform: proc {|_, code| code['class'] = %(language-#{lang || 'none'} hljs) })
end