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.



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

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

Instance Method Details

#docinfo(location, doc, opts) ⇒ Object



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

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)


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

def docinfo? location
  true
end

#format(node, lang, opts) ⇒ Object



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

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