BlockMd class abstract
Block component of the legacy regex pipeline.
A subclass is reachable only through components, which selects the legacy
pipeline: the document is rendered as one text tree, with no incremental
segment cache, no span-level streaming reveal and no lazy sliver, so a
streaming reply re-parses and re-lays-out the whole message on every
append. Register the block with MarkdownBlockComponent instead, using
FencedBlockSyntax or a MarkdownBlockSyntax subclass for the syntax; the
parsed node is cached, so a rebuild does not run the syntax again.
Before:
class CalloutMd extends BlockMd {
@override
String get expString => r':::(\w+)\n([\s\S]*?)\n:::';
@override
Widget build(
BuildContext context,
String text,
GptMarkdownConfig config,
) {
final match = exp.firstMatch(text);
return Row(
children: [
Icon(
match?.group(1) == 'warning' ? Icons.warning : Icons.info,
),
Flexible(child: Text(match?.group(2) ?? '')),
],
);
}
}
GptMarkdown(
text,
components: [CalloutMd(), ...MarkdownComponent.globalComponents],
)
After:
GptMarkdown(
text,
blockComponents: [
MarkdownBlockComponent(
syntax: const FencedBlockSyntax(
type: 'callout',
opening: ':::warning',
),
builder: (context, node, config) => Row(
children: [
const Icon(Icons.warning),
Flexible(child: Text(node.body)),
],
),
),
],
)
- Inheritance
-
- Object
- MarkdownComponent
- BlockMd
- Implementers
- Annotations
-
- @Deprecated('Use MarkdownBlockComponent with blockComponents instead. ' 'Will be removed in 2.0.0.')
Constructors
- BlockMd()
Properties
- exp → RegExp
-
no setteroverride
- expString → String
-
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- inline → bool
-
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
scopes
→ Set<
MarkdownScope> -
The nesting contexts this component is allowed to render in.
no setterinherited
Methods
-
build(
BuildContext context, String text, GptMarkdownConfig config) → Widget -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
span(
BuildContext context, String text, GptMarkdownConfig config) → InlineSpan -
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited