class Asciidoctor::SyntaxHighlighter::RougeAdapter
def create_formatter node, source, lang, opts
def create_formatter node, source, lang, opts formatter = opts[:css_mode] == :class ? (::Rouge::Formatters::HTML.new inline_theme: @style) : (::Rouge::Formatters::HTMLInline.new (::Rouge::Theme.find @style).new) if (highlight_lines = opts[:highlight_lines]) formatter = RougeExt::Formatters::HTMLLineHighlighter.new formatter, lines: highlight_lines end opts[:number_lines] ? (RougeExt::Formatters::HTMLTable.new formatter, start_line: opts[:start_line_number]) : formatter end
def create_lexer node, source, lang, opts
def create_lexer node, source, lang, opts if lang.include? '?' # NOTE cgi-style options only properly supported in Rouge >= 2.1 if (lexer = ::Rouge::Lexer.find_fancy lang) unless lexer.tag != 'php' || (node.option? 'mixed') || ((lexer_opts = lexer.options).key? 'start_inline') lexer = lexer.class.new lexer_opts.merge 'start_inline' => true end end elsif (lexer = ::Rouge::Lexer.find lang) lexer = lexer.tag == 'php' && !(node.option? 'mixed') ? (lexer.new start_inline: true) : lexer.new end if lang lexer || ::Rouge::Lexers::PlainText.new end
def docinfo location, doc, opts
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
def docinfo? location
def docinfo? location @requires_stylesheet && location == :head end
def format node, lang, opts
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
def highlight node, source, lang, opts
def highlight node, source, lang, opts @style ||= (style = opts[:style]) && (style_available? style) || DEFAULT_STYLE @requires_stylesheet = true if opts[:css_mode] == :class lexer = create_lexer node, source, lang, opts formatter = create_formatter node, source, lang, opts highlighted = formatter.format lexer.lex source if opts[:number_lines] && opts[:callouts] [highlighted, (idx = highlighted.index CodeCellStartTagCs) ? idx + CodeCellStartTagCs.length : nil] else highlighted end end
def highlight?
def highlight? library_available? end
def initialize *args
def initialize *args super @requires_stylesheet = @style = nil end
def write_stylesheet doc, to_dir
def write_stylesheet doc, to_dir ::File.write (::File.join to_dir, (stylesheet_basename @style)), (read_stylesheet @style), mode: FILE_WRITE_MODE end
def write_stylesheet? doc
def write_stylesheet? doc @requires_stylesheet end