CommonMark.jl
CommonMark.jl copied to clipboard
Disabling LinkRule (but not ImageRule) does not disable link parsing
I believe this is because the inline_rule
s for [
and ]
that go into p.inline_parser.inline_parsers
are identical for LinkRule
and ImageRule
(except that ImageRule
also triggers on !
):
https://github.com/MichaelHatherly/CommonMark.jl/blob/287e39ae128e80a6647d2d9762bf22040adffea1/src/parsers/inlines/links.jl#L271-L275
My understanding of the parser is that parse_open_bracket
will trigger anyway, because once it has been added to p.inline_parser.inline_parsers
, it doesn't know whether it was added by LinkRule
or ImageRule
.
For an MWE, setting up the parser as follows to remove LinkRule
(and it's associated inline_rule
s):
using CommonMark
p = Parser()
rules = filter(r -> !isa(r, LinkRule), p.rules)
disable!(p, copy(p.rules))
enable!(p, rules)
n = p("\n\n[x](y)")
The resulting AST still has the Link
nodes:
julia> n.first_child.first_child.t
CommonMark.Image("b", "")
julia> n.first_child.nxt.first_child.t
CommonMark.Link("y", "")
To be fair, I am not sure whether it even makes sense to disable one and not another. But if it doesn't, maybe it would make sense to merge them into a single rule?