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

SPECIAL_CHARS = { '&' => '&amp;', '<' => '&lt;', '>' => '&gt;'
SPECIAL_CHARS_PATTERN = /[#{SPECIAL_CHARS.keys.join}]/
SUBS = { :basic => [:specialcharacters], :normal => [:specialcharacters, :quotes, :attributes, :replacements, :macros, :post_replacements], :verbatim => [:specialcharacters, :callouts], :title => [:specialcharacters, :quotes, :replacements, :macros, :attributes, :post_replacements], :header => [:specialcharacters, :attributes], # by default, AsciiDoc performs :attributes and :macros on a pass block # TODO make this a compliance setting :pass => []
COMPOSITE_SUBS = { :none => [], :normal => SUBS[:normal], :verbatim => SUBS[:verbatim], :specialchars => [:specialcharacters]
SUB_SYMBOLS = { :a => :attributes, :m => :macros, :n => :normal, :p => :post_replacements, :q => :quotes, :r => :replacements, :c => :specialcharacters, :v => :verbatim
SUB_OPTIONS = { :block => COMPOSITE_SUBS.keys + SUBS[:normal] + [:callouts], :inline => COMPOSITE_SUBS.keys + SUBS[:normal]
SUB_HIGHLIGHT = ['coderay', 'pygments']
PASS_START = "\u0096"   SPA, start of guarded protected area (\u0096)
PASS_END = "\u0097"   EPA, end of guarded protected area (\u0097)
PASS_MATCH = /\u0096(\d+)\u0097/   match placeholder record
PASS_MATCH_HI = /<span[^>]*>\u0096<\/span>[^\d]*(\d+)[^\d]*<span[^>]*>\u0097<\/span>/   fix placeholder record after syntax highlighting

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.

lines - The lines of text to process. Can be a String or a String Array

returns - A String with normal substitutions performed

Public: Apply the specified substitutions to the lines of text

source - The String or String Array of text to process subs - The substitutions to perform. Can be a Symbol or a Symbol Array (default: :normal) expand - A Boolean to control whether sub aliases are expanded (default: true)

returns Either a String or String Array, whichever matches the type of the first 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 the substitutions and assigns it to the subs property on this block. Otherwise, assigns a set of default substitutions based on the content model of the block.

Returns nothing

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 text

str - A String of unprocessed attributes (space-separated roles or the id/role shorthand syntax)

returns nil if str is nil, an empty Hash if str is empty, otherwise 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

Public: Substitute special characters (i.e., encode XML)

Special characters are defined in the Asciidoctor::SPECIAL_CHARS Array constant

text - The String text to process

returns The String text with special characters replaced

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]