Skip to content

[flutter_markdown] please allow custom block elements #135848

@sma

Description

@sma

Is there an existing issue for this?

Use case

I tried to add my own custom block element using a blockSyntaxes: const [NoteSyntax()], declaration in the Markdown widget. My NoteSyntax creates an Element('note', children) which then eventually gets passed to the visitor that creates widgets.

I tried to add my own builder using builders: {'note': NoteBuilder()}, in the Markdown widget, but this is never called because MarkdownBuilder.visitElementBefore uses a private function _isBlockTag to determine whether the provided Element is a block element by comparing its tag to a hardcoded list of tags.

Therefore, it incorrectly thinks my Element is an inline element and crashes 1 because _addParentInlineIfNeeded wants add an inline element that requires a tag but the parent of my block node is the document which has no tag.

Proposal

I'd suggest to dispatch the isBlock call to the element itself – or let me extend that list.

Footnotes

  1. See line 632 of builder.dart, style: styleSheet.styles[tag!],.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterp: flutter_markdownflutter/packages flutter_markdownpackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions