Summary
#87 fixed the hard-break half of #25. The other half, which #25 also mentions, is still open: a CommonMark link reference definition ([label]: url) is read as an ordinary paragraph. So a [text][label] link that uses it does not resolve.
Reproduction (0.3.0)
from legaldown import parse_document
src = "---\ntitle: T\n---\n\n# A\n\nSee [the site][x].\n\n[x]: https://example.com\n"
print([(b.kind, b.text) for b in parse_document(src).sections[0].blocks])
# [('paragraph', 'See [the site][x].'), ('paragraph', '[x]: https://example.com')]
In CommonMark, the second block is a definition. It renders nothing, and it makes [the site][x] a link to https://example.com.
Impact
legaldown-render builds only from this model, so it renders the definition as visible text and the link as literal brackets. A renderer could parse definitions out of paragraph text itself, but that re-derives a CommonMark block rule the parser owns.
Proposal
The parser should recognise link reference definitions, and the model should expose them. For example:
- a
link_definition block kind with label, target and title, or
- a document-level
link_definitions: dict[str, (url, title)], keyed by the normalised label.
A definition can also start a paragraph or follow another one, and it can appear in list items and quotes. Serialising the model must keep it.
Found while adopting 0.3.0 in legaldown-render.
Summary
#87 fixed the hard-break half of #25. The other half, which #25 also mentions, is still open: a CommonMark link reference definition (
[label]: url) is read as an ordinary paragraph. So a[text][label]link that uses it does not resolve.Reproduction (0.3.0)
In CommonMark, the second block is a definition. It renders nothing, and it makes
[the site][x]a link tohttps://example.com.Impact
legaldown-renderbuilds only from this model, so it renders the definition as visible text and the link as literal brackets. A renderer could parse definitions out of paragraph text itself, but that re-derives a CommonMark block rule the parser owns.Proposal
The parser should recognise link reference definitions, and the model should expose them. For example:
link_definitionblock kind withlabel,targetand title, orlink_definitions: dict[str, (url, title)], keyed by the normalised label.A definition can also start a paragraph or follow another one, and it can appear in list items and quotes. Serialising the model must keep it.
Found while adopting 0.3.0 in legaldown-render.