Class: Asciidoctor::SyntaxHighlighter::HighlightJsAdapter
- Inherits:
-
Base
- Object
- Base
- Asciidoctor::SyntaxHighlighter::HighlightJsAdapter
show all
- Defined in:
- lib/asciidoctor/syntax_highlighter/highlightjs.rb
Constant Summary
DefaultFactory::PROVIDED
Instance Attribute Summary
#name
Instance Method Summary
collapse
#highlight, #highlight?, #write_stylesheet, #write_stylesheet?
#for, #register
Methods included from Factory
#create, #for, #register
Constructor Details
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 %(<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[data-lang]')).forEach(function (el) { hljs.highlightBlock(el) })
}
</script>)
end
end
|
#docinfo?(location) ⇒ Boolean
15
16
17
|
# File 'lib/asciidoctor/syntax_highlighter/highlightjs.rb', line 15
def docinfo? location
true
end
|
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
|