pub trait CosyParserExtension {
type Output;
// Required method
fn parse_bracket(&self, content: &str) -> Option<Self::Output>;
}Expand description
A trait that enables parsing of user-defined bracket syntax.
This trait allows users to inject custom syntax handling into the parser.
It provides a hook for parsing content within brackets ([...]) before
any built-in bracket parser is tried.
Implementors define their own Output type, which will be
stored in crate::ast::Node::Custom when parse_bracket
returns Some.
§Usage
Pass &() to crate::parse when no custom syntax is needed; the
blanket CosyParserExtension impl on () always returns None,
so all input falls through to the built-in parsers.
Required Associated Types§
Sourcetype Output
type Output
The type of the output produced by the custom parser.
This type is stored in crate::ast::Node::Custom when
parse_bracket returns Some.
Required Methods§
Sourcefn parse_bracket(&self, content: &str) -> Option<Self::Output>
fn parse_bracket(&self, content: &str) -> Option<Self::Output>
Parses the content inside brackets and returns an optional custom output.
This method is called before any built-in bracket parser. If it
returns Some, the bracketed sequence becomes a crate::ast::Node::Custom
holding the returned value, and built-in interpretation (links,
decorations, icons, etc.) is skipped. If it returns None, the
parser falls through to the built-in bracket parsers.
§Arguments
-
content— the string between the brackets, with the surrounding[and]removed but otherwise unmodified (no trimming, no prefix stripping). Examples:Source content[abc]"abc"[* bold]"* bold"[/ italic]"/ italic"[$ x^2]"$ x^2"
§Returns
Option<Self::Output>— the custom parsed value if thiscontentis recognized by the extension, orNoneto fall back to built-in parsers.
§Note on recursion
The returned Self::Output is treated as a terminal AST node —
cosy does not recursively re-parse the contained text. If you
need nested inline parsing, parse the relevant fragments yourself
inside the extension before constructing Self::Output.