Module Asciidoctor::Substitutors
In: lib/asciidoctor/substitutors.rb

Public: Methods to perform substitutions on lines of AsciiDoc text. This module is intented to be mixed-in to Section and Block to provide operations for performing the necessary substitutions.

Methods

Constants

SpecialCharsRx = /[<&>]/
SpecialCharsTr = { '>' => '&gt;', '<' => '&lt;', '&' => '&amp;' }
QuotedTextSniffRx = { false => /[*_`#^~]/, true => /[*'_+#^~]/ }   Detects if text is a possible candidate for the quotes substitution.
BASIC_SUBS = [:specialcharacters]).freeze
HEADER_SUBS = [:specialcharacters, :attributes]).freeze
NORMAL_SUBS = [:specialcharacters, :quotes, :attributes, :replacements, :macros, :post_replacements]).freeze
NONE_SUBS = []).freeze
TITLE_SUBS = [:specialcharacters, :quotes, :replacements, :macros, :attributes, :post_replacements]).freeze
REFTEXT_SUBS = [:specialcharacters, :quotes, :replacements]).freeze
VERBATIM_SUBS = [:specialcharacters, :callouts]).freeze
SUB_GROUPS = { :none => NONE_SUBS, :normal => NORMAL_SUBS, :verbatim => VERBATIM_SUBS, :specialchars => BASIC_SUBS
SUB_HINTS = { :a => :attributes, :m => :macros, :n => :normal, :p => :post_replacements, :q => :quotes, :r => :replacements, :c => :specialcharacters, :v => :verbatim
SUB_OPTIONS = { :block => SUB_GROUPS.keys + NORMAL_SUBS + [:callouts], :inline => SUB_GROUPS.keys + NORMAL_SUBS
SUB_HIGHLIGHT = ['coderay', 'pygments']
PASS_START = %(\u0096)   SPA, start of guarded protected area (\u0096)
PASS_END = %(\u0097)   EPA, end of guarded protected area (\u0097)
PassSlotRx = /#{PASS_START}(\d+)#{PASS_END}/   match passthrough slot
HighlightedPassSlotRx = %r(<span\b[^>]*>#{PASS_START}</span>[^\d]*(\d+)[^\d]*<span\b[^>]*>#{PASS_END}</span>)   fix passthrough slot after syntax highlighting
RS = '\\'
R_SB = ']'
ESC_R_SB = '\]'
PLUS = '+'
PygmentsWrapperDivRx = %r(<div class="pyhl">(.*)</div>)m
PygmentsWrapperPreRx = %r(<pre\b[^>]*?>(.*?)</pre>\s*)m   NOTE handles all permutations of <pre> wrapper NOTE trailing whitespace appears when pygments-linenums-mode=table; <pre> has style attribute when pygments-css=inline

Attributes

passthroughs  [R]  Internal: A String Array of passthough (unprocessed) text captured from this block

Public Instance methods

Public: Apply substitutions for header metadata and attribute assignments

text - String containing the text process

returns - A String with header substitutions performed

Public: Apply normal substitutions.

An alias for apply_subs with default remaining arguments.

text - The String text to which to apply normal substitutions

Returns the String with normal substitutions applied.

Public: Apply substitutions for reftext.

text - The String to process

Returns a String with all substitutions from the reftext substitution group applied

Public: Apply the specified substitutions to the source.

source - The String or String Array of text to process; must not be nil. subs - The substitutions to perform; can be a Symbol, Symbol Array or nil (default: NORMAL_SUBS). expand - A Boolean (or nil) to control whether substitution aliases are expanded (default: nil).

Returns a String or String Array with substitutions applied, matching the type of source argument.

Public: Apply substitutions for titles.

title - The String title to process

returns - A String with title substitutions performed

Internal: Convert a quoted text region

match - The MatchData for the quoted text region type - The quoting type (single, double, strong, emphasis, monospaced, etc) scope - The scope of the quoting (constrained or unconstrained)

Returns The converted String text for the quoted text region

Internal: Substitute replacement text for matched location

returns The String text with the replacement characters substituted

Internal: Extract the passthrough text from the document for reinsertion after processing.

text - The String from which to extract passthrough fragements

returns - The text with the passthrough region substituted with placeholders

Public: Highlight the source code if a source highlighter is defined on the document, otherwise return the text unprocessed

Callout marks are stripped from the source prior to passing it to the highlighter, then later restored in converted form, so they are not incorrectly processed by the source highlighter.

source - the source code String to highlight process_callouts - a Boolean flag indicating whether callout marks should be substituted

returns the highlighted source code, if a source highlighter is defined on the document, otherwise the source with verbatim substituions applied

Internal: Lock-in the substitutions for this block

Looks for an attribute named "subs". If present, resolves substitutions from the value of that attribute and assigns them to the subs property on this block. Otherwise, uses the substitutions assigned to the default_subs property, if specified, or selects a default set of substitutions based on the content model of the block.

Returns The Array of resolved substitutions now assigned to this block

Internal: Strip bounding whitespace and fold endlines

Internal: Parse the attributes in the attribute line

attrline - A String of unprocessed attributes (key/value pairs) posattrs - The keys for positional attributes

returns nil if attrline is nil, an empty Hash if attrline is empty, otherwise a Hash of parsed attributes

Internal: Parse the attributes that are defined on quoted (aka formatted) text

str - A non-nil String of unprocessed attributes;

      space-separated roles (e.g., role1 role2) or the id/role shorthand syntax (e.g., #idname.role)

Returns a Hash of attributes (role and id only)

e.g., highlight="1-5, !2, 10" or highlight=1-5;!2,10

Internal: Resolve the list of comma-delimited subs against the possible options.

subs - A comma-delimited String of substitution aliases

returns An Array of Symbols representing the substitution operation

Internal: Restore the passthrough text by reinserting into the placeholder positions

text - The String text into which to restore the passthrough text outer - A Boolean indicating whether we are in the outer call (default: true)

returns The String text with the passthrough text restored

Internal: Split text formatted as CSV with support for double-quoted values (in which commas are ignored)

Public: Substitute attribute references

Attribute references are in the format +{name}+.

If an attribute referenced in the line is missing, the line is dropped.

text - The String text to process

returns The String text with the attribute references replaced with attribute values

Public: Substitute callout source references

text - The String text to process

Returns the converted String text

Internal: Substitute normal and bibliographic anchors

Internal: Substitute cross reference links

Public: Substitute inline macros (e.g., links, images, etc)

Replace inline macros, which may span multiple lines, in the provided text

source - The String text to process

returns The converted String text

Public: Substitute post replacements

text - The String text to process

Returns the converted String text

Public: Substitute quoted text (includes emphasis, strong, monospaced, etc)

text - The String text to process

returns The converted String text

Public: Substitute replacement characters (e.g., copyright, trademark, etc)

text - The String text to process

returns The String text with the replacement characters substituted

Public: Apply verbatim substitutions on source (for use when highlighting is disabled).

source - the source code String on which to apply verbatim substitutions process_callouts - a Boolean flag indicating whether callout marks should be substituted

returns the substituted source

sub_specialcharacters(text)

Alias for sub_specialchars

Internal: Strip bounding whitespace, fold endlines and unescaped closing square brackets from text extracted from brackets

Internal: Unescape closing square brackets. Intended for text extracted from square brackets.

[Validate]