class Asciidoctor::Revealjs::SyntaxHighlighter::HighlightJsAdapter

Override the built-in highlight.js syntax highlighter

Constants

HIGHLIGHT_JS_VERSION
HIGHLIGHT_PLUGIN_SOURCE

this file was copied-pasted from raw.githubusercontent.com/hakimel/reveal.js/3.9.2/plugin/highlight/highlight.js please note that the bundled highlight.js code was removed so we can use the latest version from cdnjs.

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/asciidoctor-revealjs/highlightjs.rb, line 11
def initialize *args
  super
  @name = @pre_class = 'highlightjs'
end

Public Instance Methods

_convert_highlight_to_revealjs(node) click to toggle source

Convert between highlight notation formats In addition to Asciidoctor's linenum converter leveraging core's resolve_lines_to_highlight, we also support reveal.js step-by-step highlights. The steps are split using the | character For example, this method makes “1..3|6,7” into “1,2,3|6,7”

# File lib/asciidoctor-revealjs/highlightjs.rb, line 21
def _convert_highlight_to_revealjs node
  return node.attributes["highlight"].split("|").collect { |linenums|
    node.resolve_lines_to_highlight(node.content, linenums).join(",")
  }.join("|")
end
docinfo(location, doc, opts) click to toggle source
# File lib/asciidoctor-revealjs/highlightjs.rb, line 44
        def docinfo location, doc, opts
          if RUBY_ENGINE == 'opal' && JAVASCRIPT_PLATFORM == 'node'
            revealjsdir = (doc.attr :revealjsdir, 'node_modules/reveal.js')
          else
            revealjsdir = (doc.attr :revealjsdir, 'reveal.js')
          end
          if doc.attr? 'highlightjs-theme'
            theme_href = doc.attr 'highlightjs-theme'
          else
            theme_href = "#{revealjsdir}/lib/css/monokai.css"
          end
          base_url = doc.attr 'highlightjsdir', %(#{opts[:cdn_base_url]}/highlight.js/#{HIGHLIGHT_JS_VERSION})
          %(<link rel="stylesheet" href="#{theme_href}"#{opts[:self_closing_tag_slash]}>
<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>
#{HIGHLIGHT_PLUGIN_SOURCE}
hljs.initHighlightingOnLoad();
</script>)
        end
docinfo?(location) click to toggle source
# File lib/asciidoctor-revealjs/highlightjs.rb, line 40
def docinfo? location
  location == :footer
end
format(node, lang, opts) click to toggle source
Calls superclass method
# File lib/asciidoctor-revealjs/highlightjs.rb, line 27
def format node, lang, opts
  super node, lang, (opts.merge transform: proc { |_, code|
    code['class'] = %(language-#{lang || 'none'} hljs)
    code['data-noescape'] = true

    if node.attributes.key?("highlight")
      code['data-line-numbers'] = self._convert_highlight_to_revealjs(node)
    elsif node.attributes.key?("linenums")
      code['data-line-numbers'] = ''
    end
  })
end