# frozen_string_literal: true
module Asciidoctor
class SyntaxHighlighter::HighlightJsAdapter < SyntaxHighlighter::Base
register_for 'highlightjs', 'highlight.js'
def initialize *args
super
@name = @pre_class = 'highlightjs'
end
def format node, lang, opts
super node, lang, (opts.merge transform: proc {|_, code| code['class'] = %(language-#{lang || 'none'} hljs) })
end
def docinfo? location
true
end
def docinfo location, doc, opts
base_url = doc.attr 'highlightjsdir', %(#{opts[:cdn_base_url]}/highlight.js/#{HIGHLIGHT_JS_VERSION})
if location == :head
%()
else # :footer
%(
#{(doc.attr? 'highlightjs-languages') ? ((doc.attr 'highlightjs-languages').split ',').map {|lang| %[\n] }.join : ''})
end
end
end
end