class Asciidoctor::Prawn::CodeRayEncoder
Constants
- COLORS
Manni theme from
Pygments
- GuardedIndent
- GuardedInnerIndent
- InnerIndent
- LF
- NoBreakSpace
Public Instance Methods
begin_group(kind)
click to toggle source
# File lib/asciidoctor/pdf/ext/prawn/coderay_encoder.rb, line 108 def begin_group kind @open << kind end
end_group(_kind)
click to toggle source
# File lib/asciidoctor/pdf/ext/prawn/coderay_encoder.rb, line 112 def end_group _kind @open.pop end
setup(options)
click to toggle source
Calls superclass method
# File lib/asciidoctor/pdf/ext/prawn/coderay_encoder.rb, line 79 def setup options super @out = [] @open = [] # NOTE tracks whether text token begins at the start of a line @start_of_line = true end
text_token(text, kind)
click to toggle source
# File lib/asciidoctor/pdf/ext/prawn/coderay_encoder.rb, line 87 def text_token text, kind if text == LF @out << { text: text } @start_of_line = true # NOTE text is nil and kind is :error when CodeRay ends parsing on an error elsif text # NOTE add guard character to prevent Prawn from trimming indentation text[0] = GuardedIndent if @start_of_line && (text.start_with? ' ') text.gsub! InnerIndent, GuardedInnerIndent if text.include? InnerIndent # NOTE this optimization assumes we don't support/use background colors if text.rstrip.empty? @out << { text: text } else # QUESTION should we default to no color? @out << { text: text, color: (COLORS[kind] || COLORS[@open[-1]] || COLORS[:default]) } end @start_of_line = text.end_with? LF end end