class Asciidoctor::Rouge::PassthroughsSubstitutor

A substitutor for processing passthroughs inside listing blocks. It's basically just a facade for Asciidoctor's internal methods.

Constants

PASS_END_MARK
PASS_SLOT_RX
PASS_START_MARK

Public Class Methods

create(node) click to toggle source

@param node [Asciidoctor::AbstractNode] @return [PassthroughsSubstitutor] a passthroughs substitutor for

the given *node*.
# File lib/asciidoctor/rouge/passthroughs_substitutor.rb, line 17
def self.create(node)
  new(node)
end
new(node) click to toggle source

(see .create)

# File lib/asciidoctor/rouge/passthroughs_substitutor.rb, line 49
def initialize(node)
  @node = node
end

Public Instance Methods

extract(text) click to toggle source

Extracts passthrough regions from the given text for reinsertion after processing.

@param text [String] the source of the node. @return [String] a copy of the text with passthrough regions

substituted with placeholders.
# File lib/asciidoctor/rouge/passthroughs_substitutor.rb, line 27
def extract(text)
  @node.extract_passthroughs(text)
end
restore(text) click to toggle source

Restores the extracted passthroughs by reinserting them into the placeholder positions.

@param text [String] the text into which to restore the passthroughs. @return [String] a copy of the text with restored passthroughs.

# File lib/asciidoctor/rouge/passthroughs_substitutor.rb, line 36
def restore(text)
  return text if @node.passthroughs.empty?

  # Fix passthrough placeholders that got caught up in syntax highlighting.
  text = text.gsub(PASS_SLOT_RX, "#{PASS_START_MARK}\\1#{PASS_END_MARK}")

  # Restore converted passthroughs.
  @node.restore_passthroughs(text)
end