JuliaDocs / MarkdownAST.jl

Abstract syntax tree representation of Markdown documents in Julia
https://juliadocs.github.io/MarkdownAST.jl
Other
13 stars 3 forks source link

Backslash / soft break / line break elements #7

Open mortenpi opened 2 years ago

mortenpi commented 2 years ago

CommonMark has implemented dedicated inlines for these characters. But do we actually need them here?

https://github.com/JuliaDocs/MarkdownAST.jl/blob/72c5f6c2e9ae51a0c66a4bf8213a31f6cdac9a09/src/markdown.jl#L467-L469

mortenpi commented 2 years ago

A few notes for this:

I wonder how to handle Text() elements that contain newlines and backlashes, however. It seems that for backslashes, we can anyway end up with literal backslashes in the text, but the cases where it resembles a escape sequence could be problematic. Similarly, newlines in the text could be a problem.

One option would be disallow these characters when constructing Text(). Otherwise, the consumers have to assume that the nodes can contain weird backlashes and newlines.

However, this would be annoying when constructing trees programmatically (as opposed to parsing Markdown). To work around that, we could provide e.g. an inlinetext function that does some simple inline parsing into LineBreak etc nodes (e.g. inlinetext("foo\\\nbar") -> [Text("foo"), LineBreak(), Text("bar")]).