Skip to content

Support for custom Markup classes #263

@relikd

Description

@relikd

Hi, I am trying to replicate Github's alert banners:

Note

like this

> [!NOTE]
> like this

The parser would need to decide at the block-quote level, whether the first Text child is some pre-defined string. If so, the parser would then need to remove the first child and assign an enum category to the alert banner.

Ideally I would create a MarkupRewriter and return a new type in

func visitBlockQuote(_ blockQuote: BlockQuote)

But I dont see any way to extend the existing markup types. I could implement a struct AlertBlock: BlockMarkup but the protocol requires a MarkupVisitor which cannot be a subclass protocol.

My only workaround is to introduce a complicated state-machine into my HTML formatter to ignore the first Text child element, if a parent blockquote is alert banner style.

(side question:
this does not work. Is the MarkupWalker not allowed to change text?

var alertTag = blockQuote.child(at: 0)?.child(at: 0) as? Text
alertTag?.string = ""

)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions