class Asciidoctor::SyntaxHighlighter::PygmentsAdapter
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
Asciidoctor::SyntaxHighlighter::new
# File lib/asciidoctor/syntax_highlighter/pygments.rb, line 6 def initialize *args super @requires_stylesheet = @style = nil end
Public Instance Methods
docinfo(location, doc, opts)
click to toggle source
# File lib/asciidoctor/syntax_highlighter/pygments.rb, line 64 def docinfo location, doc, opts if opts[:linkcss] %(<link rel="stylesheet" href="#{doc.normalize_web_path (stylesheet_basename @style), (doc.attr 'stylesdir', ''), false}"#{opts[:self_closing_tag_slash]}>) else %(<style> #{read_stylesheet @style} </style>) end end
docinfo?(location)
click to toggle source
# File lib/asciidoctor/syntax_highlighter/pygments.rb, line 60 def docinfo? location @requires_stylesheet && location == :head end
format(node, lang, opts)
click to toggle source
Calls superclass method
Asciidoctor::SyntaxHighlighter::Base#format
# File lib/asciidoctor/syntax_highlighter/pygments.rb, line 52 def format node, lang, opts if opts[:css_mode] != :class && (@style = (style = opts[:style]) && (style_available? style) || DEFAULT_STYLE) && (pre_style_attr_val = base_style @style) opts[:transform] = proc {|pre| pre['style'] = pre_style_attr_val } end super end
highlight(node, source, lang, opts)
click to toggle source
# File lib/asciidoctor/syntax_highlighter/pygments.rb, line 15 def highlight node, source, lang, opts lexer = (::Pygments::Lexer.find_by_alias lang) || (::Pygments::Lexer.find_by_mimetype 'text/plain') @requires_stylesheet = true unless (noclasses = opts[:css_mode] != :class) highlight_opts = { classprefix: TOKEN_CLASS_PREFIX, cssclass: WRAPPER_CLASS, nobackground: true, noclasses: noclasses, startinline: lexer.name == 'PHP' && !(node.option? 'mixed'), stripnl: false, style: (@style ||= (style = opts[:style]) && (style_available? style) || DEFAULT_STYLE), } if (highlight_lines = opts[:highlight_lines]) highlight_opts[:hl_lines] = highlight_lines.join ' ' end if (linenos = opts[:number_lines]) && (highlight_opts[:linenostart] = opts[:start_line_number]) && (highlight_opts[:linenos] = linenos) == :table if (highlighted = lexer.highlight source, options: highlight_opts) highlighted = highlighted.sub StyledLinenoColumnStartTagsRx, LinenoColumnStartTagsCs if noclasses highlighted = highlighted.sub WrapperTagRx, PreTagCs opts[:callouts] ? [highlighted, (idx = highlighted.index CodeCellStartTagCs) ? idx + CodeCellStartTagCs.length : nil] : highlighted else node.sub_source source, false # handles nil response from ::Pygments::Lexer#highlight end elsif (highlighted = lexer.highlight source, options: highlight_opts) if linenos if noclasses highlighted = highlighted.gsub StyledLinenoSpanTagRx, LinenoSpanTagCs elsif highlighted.include? LegacyLinenoSpanStartTagCs highlighted = highlighted.gsub LegacyLinenoSpanTagRx, LinenoSpanTagCs end end highlighted.sub WrapperTagRx, '\1' else node.sub_source source, false # handles nil response from ::Pygments::Lexer#highlight end end
highlight?()
click to toggle source
# File lib/asciidoctor/syntax_highlighter/pygments.rb, line 11 def highlight? library_available? end
write_stylesheet(doc, to_dir)
click to toggle source
# File lib/asciidoctor/syntax_highlighter/pygments.rb, line 78 def write_stylesheet doc, to_dir ::File.write (::File.join to_dir, (stylesheet_basename @style)), (read_stylesheet @style), mode: FILE_WRITE_MODE end
write_stylesheet?(doc)
click to toggle source
# File lib/asciidoctor/syntax_highlighter/pygments.rb, line 74 def write_stylesheet? doc @requires_stylesheet end