class Asciidoctor::SyntaxHighlighter::RougeAdapter
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
Asciidoctor::SyntaxHighlighter.new
# File lib/asciidoctor/syntax_highlighter/rouge.rb, line 5 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/rouge.rb, line 51 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/rouge.rb, line 47 def docinfo? location @requires_stylesheet && location == :footer end
format(node, lang, opts)
click to toggle source
Calls superclass method
Asciidoctor::SyntaxHighlighter::Base#format
# File lib/asciidoctor/syntax_highlighter/rouge.rb, line 36 def format node, lang, opts if (query_idx = lang && (lang.index '?')) lang = lang.slice 0, query_idx end 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/rouge.rb, line 14 def highlight node, source, lang, opts lexer = (::Rouge::Lexer.find_fancy lang) || ::Rouge::Lexers::PlainText lexer_opts = lexer.tag == 'php' && !(node.option? 'mixed') ? { start_inline: true } : {} @style ||= (style = opts[:style]) && (style_available? style) || DEFAULT_STYLE if opts[:css_mode] == :class @requires_stylesheet = true formatter = ::Rouge::Formatters::HTML.new inline_theme: @style else formatter = ::Rouge::Formatters::HTMLInline.new (::Rouge::Theme.find @style).new end if (highlight_lines = opts[:highlight_lines]) formatter = RougeExt::Formatters::HTMLLineHighlighter.new formatter, lines: highlight_lines end if opts[:number_lines] formatter = RougeExt::Formatters::HTMLTable.new formatter, start_line: opts[:start_line_number] if opts[:callouts] return [(highlighted = formatter.format lexer.lex source, lexer_opts), (idx = highlighted.index CodeCellStartTagCs) ? idx + CodeCellStartTagCs.length : nil] end end formatter.format lexer.lex source, lexer_opts end
highlight?()
click to toggle source
# File lib/asciidoctor/syntax_highlighter/rouge.rb, line 10 def highlight? library_available? end
write_stylesheet(doc, to_dir)
click to toggle source
# File lib/asciidoctor/syntax_highlighter/rouge.rb, line 65 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/rouge.rb, line 61 def write_stylesheet? doc @requires_stylesheet end