Parser

Struct Parser 

Source
pub struct Parser {
    pub path_resolver: PathResolver,
    /* private fields */
}
Expand description

The Parser struct and its related structs allow a caller to configure how AsciiDoc parsing occurs and then to initiate the parsing process.

Fields§

§path_resolver: PathResolver

Specifies how to generate clean and secure paths relative to the parsing context.

Implementations§

Source§

impl Parser

Source

pub fn parse(&mut self, source: &str) -> Document<'static>

Parse a UTF-8 string as an AsciiDoc document.

The Document data structure returned by this call has a ’static lifetime; this is an implementation detail. It retains a copy of the source string that was passed in, but it is not tied to the lifetime of that string.

Nearly all of the data structures contained within the Document structure are tied to the lifetime of the document and have a 'src lifetime to signal their dependency on the source document.

IMPORTANT: The AsciiDoc language documentation states that UTF-16 encoding is allowed if a byte-order-mark (BOM) is present at the start of a file. This format is not directly supported by the asciidoc-parser crate. Any UTF-16 content must be re-encoded as UTF-8 prior to parsing.

The Parser struct will be updated with document attribute values discovered during parsing. These values may be inspected using attribute_value().

§Warnings, not errors

Any UTF-8 string is a valid AsciiDoc document, so this function does not return an Option or Result data type. There may be any number of character sequences that have ambiguous or potentially unintended meanings. For that reason, a caller is advised to review the warnings provided via the warnings() iterator.

Source

pub fn attribute_value<N: AsRef<str>>(&self, name: N) -> InterpretedValue

Retrieves the current interpreted value of a document attribute.

Each document holds a set of name-value pairs called document attributes. These attributes provide a means of configuring the AsciiDoc processor, declaring document metadata, and defining reusable content. This page introduces document attributes and answers some questions about the terminology used when referring to them.

§What are document attributes?

Document attributes are effectively document-scoped variables for the AsciiDoc language. The AsciiDoc language defines a set of built-in attributes, and also allows the author (or extensions) to define additional document attributes, which may replace built-in attributes when permitted.

Built-in attributes either provide access to read-only information about the document and its environment or allow the author to configure behavior of the AsciiDoc processor for a whole document or select regions. Built-in attributes are effectively unordered. User-defined attribute serve as a powerful text replacement tool. User-defined attributes are stored in the order in which they are defined.

Source

pub fn has_attribute<N: AsRef<str>>(&self, name: N) -> bool

Returns true if the parser has a document attribute by this name.

Source

pub fn is_attribute_set<N: AsRef<str>>(&self, name: N) -> bool

Returns true if the parser has a document attribute by this name which has been set (i.e. is present and not unset).

Source

pub fn with_intrinsic_attribute<N: AsRef<str>, V: AsRef<str>>( self, name: N, value: V, modification_context: ModificationContext, ) -> Self

Sets the value of an intrinsic attribute.

Intrinsic attributes are set automatically by the processor. These attributes provide information about the document being processed (e.g., docfile), the security mode under which the processor is running (e.g., safe-mode-name), and information about the user’s environment (e.g., user-home).

The modification_context establishes whether the value can be subsequently modified by the document header and/or in the document body.

Subsequent calls to this function or with_intrinsic_attribute_bool() are always permitted. The last such call for any given attribute name takes precendence.

Source

pub fn with_intrinsic_attribute_bool<N: AsRef<str>>( self, name: N, value: bool, modification_context: ModificationContext, ) -> Self

Sets the value of an intrinsic attribute from a boolean flag.

A boolean true is interpreted as “set.” A boolean false is interpreted as “unset.”

Intrinsic attributes are set automatically by the processor. These attributes provide information about the document being processed (e.g., docfile), the security mode under which the processor is running (e.g., safe-mode-name), and information about the user’s environment (e.g., user-home).

The modification_context establishes whether the value can be subsequently modified by the document header and/or in the document body.

Subsequent calls to this function or with_intrinsic_attribute() are always permitted. The last such call for any given attribute name takes precendence.

Source

pub fn with_inline_substitution_renderer<ISR: InlineSubstitutionRenderer + 'static>( self, renderer: ISR, ) -> Self

Replace the default InlineSubstitutionRenderer for this parser.

The default implementation of InlineSubstitutionRenderer that is provided is suitable for HTML5 rendering. If you are targeting a different back-end rendering, you will need to provide your own implementation and set it using this call before parsing.

Source

pub fn with_primary_file_name<S: AsRef<str>>(self, name: S) -> Self

Sets the name of the primary file to be parsed when parse() is called.

This name will be used for any error messages detected in this file and also will be passed to IncludeFileHandler::resolve_target() as the source argument for any include:: file resolution requests from this file.

Source

pub fn with_include_file_handler<IFH: IncludeFileHandler + 'static>( self, handler: IFH, ) -> Self

Sets the IncludeFileHandler for this parser.

The include file handler is responsible for resolving include:: directives encountered during preprocessing. If no handler is provided, include directives will be ignored.

Trait Implementations§

Source§

impl Clone for Parser

Source§

fn clone(&self) -> Parser

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Parser

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Parser

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Parser

§

impl !RefUnwindSafe for Parser

§

impl !Send for Parser

§

impl !Sync for Parser

§

impl Unpin for Parser

§

impl !UnwindSafe for Parser

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.