class Asciidoctor::SyntaxHighlighter::CodeRayAdapter
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
Asciidoctor::SyntaxHighlighter::new
# File lib/asciidoctor/syntax_highlighter/coderay.rb, line 6 def initialize *args super @pre_class = 'CodeRay' @requires_stylesheet = nil end
Public Instance Methods
docinfo(location, doc, opts)
click to toggle source
# File lib/asciidoctor/syntax_highlighter/coderay.rb, line 38 def docinfo location, doc, opts if opts[:linkcss] %(<link rel="stylesheet" href="#{doc.normalize_web_path stylesheet_basename, (doc.attr 'stylesdir', ''), false}"#{opts[:self_closing_tag_slash]}>) else %(<style> #{read_stylesheet} </style>) end end
docinfo?(location)
click to toggle source
# File lib/asciidoctor/syntax_highlighter/coderay.rb, line 34 def docinfo? location @requires_stylesheet && location == :head end
highlight(node, source, lang, opts)
click to toggle source
# File lib/asciidoctor/syntax_highlighter/coderay.rb, line 16 def highlight node, source, lang, opts @requires_stylesheet = true if (css_mode = opts[:css_mode]) == :class lang = lang ? (::CodeRay::Scanners[lang = lang.to_sym] && lang rescue :text) : :text highlighted = ::CodeRay::Duo[lang, :html, css: css_mode, line_numbers: (line_numbers = opts[:number_lines]), line_number_start: opts[:start_line_number], line_number_anchors: false, highlight_lines: opts[:highlight_lines], bold_every: false, ].highlight source if line_numbers == :table && opts[:callouts] [highlighted, (idx = highlighted.index CodeCellStartTagCs) ? idx + CodeCellStartTagCs.length : nil] else highlighted end end
highlight?()
click to toggle source
# File lib/asciidoctor/syntax_highlighter/coderay.rb, line 12 def highlight? library_available? end
write_stylesheet(doc, to_dir)
click to toggle source
# File lib/asciidoctor/syntax_highlighter/coderay.rb, line 52 def write_stylesheet doc, to_dir ::File.write (::File.join to_dir, stylesheet_basename), read_stylesheet, mode: FILE_WRITE_MODE end
write_stylesheet?(doc)
click to toggle source
# File lib/asciidoctor/syntax_highlighter/coderay.rb, line 48 def write_stylesheet? doc @requires_stylesheet end