Class: Asciidoctor::SyntaxHighlighter::PrettifyAdapter

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

Returns a new instance of PrettifyAdapter.



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

def initialize *args
  super
  @pre_class = 'prettyprint'
end

Instance Method Details

#docinfo(location, doc, opts) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/asciidoctor/syntax_highlighter/prettify.rb', line 20

def docinfo location, doc, opts
  base_url = doc.attr 'prettifydir', %(#{opts[:cdn_base_url]}/prettify/r298)
  if location == :head
    prettify_theme_url = ((prettify_theme = doc.attr 'prettify-theme', 'prettify').start_with? 'http://', 'https://') ? prettify_theme : %(#{base_url}/#{prettify_theme}.min.css)
    %(<link rel="stylesheet" href="#{prettify_theme_url}"#{opts[:self_closing_tag_slash]}>)
  else # :footer
    %(<script src="#{base_url}/run_prettify.min.js"></script>)
  end
end

#docinfo?(location) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/asciidoctor/syntax_highlighter/prettify.rb', line 16

def docinfo? location
  true
end

#format(node, lang, opts) ⇒ Object



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

def format node, lang, opts
  opts[:transform] = proc {|pre| pre['class'] += %( #{(start = node.attr 'start') ? %[linenums:#{start}] : 'linenums'}) } if node.attr? 'linenums'
  super
end