Docsv3.31.0
Back to API Reference
Class

MathParseRule

sealed
Inherits:ParseRule

Replaces a formula with one layout placeholder while preserving its source as the modifier parameter: from <math>...</math> tags or LaTeX math delimiters, as Delimiters selects.

Remarks

A display formula stands in a paragraph of its own, and a \\ right after it ends an empty line, as in LaTeX, where the paragraph resumes after a display; spaces around it vanish as LaTeX ignores them. An environment such as align reaches the formula whole, its & and \\ aligning the lines and its name deciding the numbering. A formula without a closing delimiter stays text.
public MathDelimiters Delimiters{ get; set }

Gets or sets the syntax formulas are read from.

public int Priority{ get }

Gets the matching priority. Higher values are matched first. Default is 0. Use positive values for explicit markup, negative for auto-detection.

public bool CanWrap{ get }

Whether Apply emits a content-wrapping form — i.e. the rule can express an inline style application. Rules that override Apply to return syntax must also override this; consumers gate on it instead of probing Apply with empty input.

public string SourceToken{ get }

The source-markup token this rule's syntax is externally known by — whatever form the syntax takes (color for a tag rule, a marker for a marker rule) — or null for a markerless rule. Interop consumers (clipboard bindings) pair rules with format schemas by this token instead of testing syntax families.

public string Identity{ get }

Stable identity shared by rule instances that match the same syntax, compared case-insensitively — pairs separately configured instances (style merging, ByRule chrome selectors). The default (full type name) is correct for configuration-free rules. A rule whose instances can be configured to match different syntaxes MUST qualify it (TagRule → "tag:" + name, marker rule → "marker:" + marker) or return null (identity by reference only) — otherwise differently configured instances are falsely treated as the same rule. Called on hot paths — cache the string, don't rebuild it per access.

public string MarkupTriggers{ get }

Characters of which at least one must start any match of this rule that alters the visible text — strips markup (tags, markers), replaces it, or inserts content. Empty = the rule never consumes text (style-only matches like raw-URL detection); null (default) = unknown, callers must assume any text can be consumed. Literal-paste escaping protects exactly these characters, so under-reporting silently mutates pasted text.

public string TypingTriggers{ get }

Characters whose insertion or removal can make this rule begin or complete a consuming markup match. The editable document parses typed syntax only when an edit contains one of these characters or touches its immediate boundary; empty means this rule has no source syntax, while null conservatively parses every direct typing edit. Include closing delimiters and required separators, not only match starts.

public override void Reset()

Resets the rule state for a new parse operation.

public override int TryMatch(ReadOnlySpan<char> text, int index, PooledList<ParsedRange> results)

Attempts to match a pattern starting at the specified index.

public override string Apply(ReadOnlySpan<char> content, string parameter)

Emits this rule's source syntax wrapping content — the inverse of parsing, used by the editing layer to apply a style and to reconstruct copied markup. Returns null when the rule has no content-wrapping form (void, block, or composite rules), meaning it cannot be applied as an inline style.