Markdown is hierarchical. InlinePattern allows you to restrict where a pattern is applied using scopes to prevent rendering bugs and unintended matches.
Available Scopes
content: Ordinary document and inline text.linkLabel: Inside the label of a [label](url) link.tableCell: Inside a table cell.heading: Inside a # heading.
Critical Warning: Nesting in Link Labels
By default, InlinePattern uses MarkdownComponent.allScopesExceptLinkLabel.
Do not return a WidgetSpan inside a linkLabel scope. On iOS, returning a WidgetSpan inside a link label (which is already wrapped in a WidgetSpan) creates a nested placeholder that is invisible. If your pattern needs to work inside link labels, ensure your builder returns a TextSpan.
// Safe for nesting in link labels
InlinePattern(
pattern: RegExp(r'GH-\d+'),
builder: (context, match, style) => TextSpan(text: match.group(0)!),
scopes: MarkdownComponent.allScopes,
)
// Restricted to prose only
InlinePattern(
pattern: RegExp(r'#token'),
builder: (context, match, style) => TextSpan(text: match.group(0)!),
scopes: const {MarkdownScope.content},
)