Implement Pandoc Markdown concise link extension (#20304)

* Implement Pandoc Markdown concise link extension

This implements https://github.com/nim-lang/Nim/issues/20127.
Besides reference to headings we also support doing references
to Nim symbols inside Nim modules.

Markdown:
```
Some heading
------------

Ref. [Some heading].
```

Nim:
```
proc someFunction*() ...

... ## Ref. [someFunction]
```

This is substitution for RST syntax like `` `target`_ ``.
All 3 syntax variants of extension from Pandoc Markdown are supported:
`[target]`, `[target][]`, `[description][target]`.

This PR also fixes clashes in existing files, particularly
conflicts with RST footnote feature, which does not work with
this PR (but there is a plan to adopt a popular [Markdown footnote
extension](https://pandoc.org/MANUAL.html#footnotes) to make footnotes work).

Also the PR fixes a bug that Markdown links did not work when `[...]`
section had a line break.

The implementation is straightforward since link resolution did not
change w.r.t. RST implementation, it's almost only about new syntax
addition. The only essential difference is a possibility to add a custom
link description: form `[description][target]` which does not have an
RST equivalent.

* fix nim 1.0 gotcha
This commit is contained in:
Andrey Makarov 2022-09-04 21:52:21 +03:00 • committed by GitHub
commit cde6b2aab8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 325 additions and 152 deletions

View file

@ -1173,7 +1173,7 @@ suite "Warnings":
lastParagraph
"""
var warnings = new seq[string]
let output = input.toAst(warnings=warnings)
let output = input.toAst(rstOptions=preferRst, warnings=warnings)
check(warnings[] == @[
"input(3, 14) Warning: broken link 'citation-som'",
"input(5, 7) Warning: broken link 'a broken Link'",
@ -1199,7 +1199,7 @@ suite "Warnings":
rnParagraph
rnLeaf 'here'
rnLeaf ' '
rnRef
rnRstRef
rnLeaf 'brokenLink'
""")
removeFile("other.rst")
@ -1558,7 +1558,7 @@ suite "RST inline markup":
test "no punctuation in the end of a standalone URI is allowed":
check(dedent"""
[see (http://no.org)], end""".toAst ==
[see (http://no.org)], end""".toAst(rstOptions = preferRst) ==
dedent"""
rnInner
rnLeaf '['
@ -1606,6 +1606,19 @@ suite "RST inline markup":
rnLeaf 'end'
""")
test "Markdown-style link can be split to a few lines":
check(dedent"""
is [term-rewriting
macros](manual.html#term-rewriting-macros)""".toAst ==
dedent"""
rnInner
rnLeaf 'is'
rnLeaf ' '
rnHyperlink
rnLeaf 'term-rewriting macros'
rnLeaf 'manual.html#term-rewriting-macros'
""")
test "URL with balanced parentheses (Markdown rule)":
# 2 balanced parens, 1 unbalanced:
check(dedent"""