Class: Asciidoctor::Rouge::PassthroughsSubstitutor

Inherits:
Object
  • Object
show all
Defined in:
lib/asciidoctor/rouge/passthroughs_substitutor.rb

Overview

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

Constant Summary collapse

PASS_START_MARK =
::Asciidoctor::Substitutors::PASS_START
PASS_END_MARK =
::Asciidoctor::Substitutors::PASS_END
PASS_SLOT_RX =
::Asciidoctor::Substitutors::HighlightedPassSlotRx

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(node) ⇒ PassthroughsSubstitutor

Returns a passthroughs substitutor for the given node.

Parameters:

  • node (Asciidoctor::AbstractNode)

Returns:


17
18
19
# File 'lib/asciidoctor/rouge/passthroughs_substitutor.rb', line 17

def self.create(node)
  new(node)
end

Instance Method Details

#extract(text) ⇒ String

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

Parameters:

  • text (String)

    the source of the node.

Returns:

  • (String)

    a copy of the text with passthrough regions substituted with placeholders.


27
28
29
# File 'lib/asciidoctor/rouge/passthroughs_substitutor.rb', line 27

def extract(text)
  @node.extract_passthroughs(text)
end

#restore(text) ⇒ String

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

Parameters:

  • text (String)

    the text into which to restore the passthroughs.

Returns:

  • (String)

    a copy of the text with restored passthroughs.


36
37
38
39
40
41
42
43
44
# 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