Class: Asciidoctor::Rouge::Treeprocessor
- Inherits:
-
Extensions::Treeprocessor
- Object
- Extensions::Treeprocessor
- Asciidoctor::Rouge::Treeprocessor
- Defined in:
- lib/asciidoctor/rouge/treeprocessor.rb
Overview
An Asciidoctor extension that highlights source listings using Rouge.
Instance Method Summary collapse
-
#initialize(formatter: HtmlFormatter, formatter_opts: {}, callouts_sub: CalloutsSubstitutor, passthroughs_sub: PassthroughsSubstitutor) ⇒ Treeprocessor
constructor
A new instance of Treeprocessor.
- #process(document) ⇒ void
Constructor Details
#initialize(formatter: HtmlFormatter, formatter_opts: {}, callouts_sub: CalloutsSubstitutor, passthroughs_sub: PassthroughsSubstitutor) ⇒ Treeprocessor
Returns a new instance of Treeprocessor.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/asciidoctor/rouge/treeprocessor.rb', line 30 def initialize(formatter: HtmlFormatter, formatter_opts: {}, callouts_sub: CalloutsSubstitutor, passthroughs_sub: PassthroughsSubstitutor, **) super @formatter = formatter @formatter_opts = formatter_opts @callouts_sub = callouts_sub @passthroughs_sub = passthroughs_sub end |
Instance Method Details
#process(document) ⇒ void
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/asciidoctor/rouge/treeprocessor.rb', line 43 def process(document) return unless document.attr? 'source-highlighter', 'rouge' document.find_by(context: :listing, style: 'source') do |block| process_listing(block) end # Table cells may contain listing, but Document#find_by does not search # inside table, so we must handle it specially. document.find_by(context: :table) do |table| table.rows.body.each do |row| row.each do |cell| if (inner = cell.inner_document) inner.find_by(context: :listing, style: 'source') do |block| process_listing(block) end end end end end end |