apple/swift-markdown

How to add custom syntax ?

Closed this issue · 1 comments

tienll commented

How to add custom syntax to support latex or something else?

You can write custom "directives". If you're implementing a MarkupVisitor/MarkupRewriter you need to implement visitBlockDirective.

The syntax is a leading @ symbol, a name, an optional argument list with the first argument name being optional, and an optional {} brace delimited child document.

For example:

@LaTeX {
    This is a \LaTeX{} document
}

This would parse as a BlockDirective with name LaTeX, and children being a Text element containing the text. From here you can extract this, replace it with something else, or do whatever you like.