Docsv3.31.0
Back to API Reference
Class

TriggerWordParseRule

sealed
Inherits:ParseRule

Auto-detects <trigger>word tokens in plain text (mentions, hashtags) and produces a style-only range per token whose parameter is the word without the trigger.

Remarks

The trigger character is serialized — nothing is hardcoded. The word charset is Unicode letters, digits and underscore, extendable through ExtraWordChars (e.g. "-." for handles that allow them). A match requires the trigger at a word start: the preceding character must not be a word character or another trigger, and at least one word character must follow — so e-mail addresses (user@host) and doubled triggers stay plain text. Style-only: the trigger and word remain visible, nothing is consumed. Runs at negative priority so explicit markup (tags, Markdown) wins where they overlap.
public string Trigger{ get; set }

Trigger prefix; only the first character starts a match. Null or empty disables the rule.

public string ExtraWordChars{ get; set }

Characters allowed in the word besides Unicode letters, digits and underscore.

public string DefaultParameter{ get; set }

Merged behind the detected word (the word itself stays the opaque first value).

public int Priority{ get }

Low priority ensures this runs after explicit markup rules.

public string MarkupTriggers{ get }

Style-only matches — the trigger and word stay on screen, nothing is consumed.

public string TypingTriggers{ get }
public string ScanTriggers{ get }

Characters of which at least one must be at the match position for TryMatch to succeed at all (consuming or style-only). Defaults to MarkupTriggers — override when the rule matches at characters beyond its consuming set (raw-URL scheme letters). The parser bakes the union into a jump table and skips runs of non-trigger text, so an accurate set here is a large parse speedup; null disables the fast scan for the whole component.

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.

[ctor]public TriggerWordParseRule()
[ctor]public TriggerWordParseRule(string trigger)
public override int TryMatch(ReadOnlySpan<char> text, int index, PooledList<ParsedRange> results)

Attempts to match a pattern starting at the specified index.

See Also