Skip to main content

substitute

Function substitute 

Source
pub fn substitute<'a, 'b>(
    text: &'b str,
    substitutions: &[Substitution],
    attributes: &DocumentAttributes<'a>,
) -> Cow<'b, str>
where 'a: 'b,
Expand description

Apply a sequence of substitutions to text.

Iterates through the substitution list and applies each in order:

  • Attributes - Expands {name} references using document attributes
  • Normal / Verbatim - Recursively applies the corresponding substitution group
  • All others (SpecialChars, Quotes, Replacements, Macros, PostReplacements, Callouts) - No-op; handled by the converter (SpecialChars, Quotes, Replacements) or by the grammar (Macros, PostReplacements, Callouts).

ยงExample

use acdc_parser::{Options, Substitution, substitute};

let options = Options::with_attributes([("version", "1.0")])?;
let attrs = options.document_attributes();

let result = substitute("Version {version}", &[Substitution::Attributes], attrs);
assert_eq!(result, "Version 1.0");