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:
parent
b931e74a59
commit
cde6b2aab8
23 changed files with 325 additions and 152 deletions
|
|
@ -983,7 +983,7 @@ Test1
|
|||
|
||||
Ref. [#note]_
|
||||
"""
|
||||
let output1 = input1.toHtml
|
||||
let output1 = input1.toHtml(preferRst)
|
||||
doAssert output1.count(">[1]</a>") == 1
|
||||
doAssert output1.count(">[2]</a>") == 2
|
||||
doAssert "href=\"#footnote-note\"" in output1
|
||||
|
|
@ -1001,7 +1001,7 @@ Test1
|
|||
|
||||
Not references[#note]_[1 #]_ [wrong citation]_ and [not&allowed]_.
|
||||
"""
|
||||
let output2 = input2.toHtml
|
||||
let output2 = input2.toHtml(preferRst)
|
||||
doAssert output2 == "Not references[#note]_[1 #]_ [wrong citation]_ and [not&allowed]_."
|
||||
|
||||
# check that auto-symbol footnotes work:
|
||||
|
|
@ -1017,7 +1017,7 @@ Test1
|
|||
|
||||
And [*]_.
|
||||
"""
|
||||
let output3 = input3.toHtml
|
||||
let output3 = input3.toHtml(preferRst)
|
||||
# both references and footnotes. Footnotes have link to themselves.
|
||||
doAssert output3.count("href=\"#footnotesym-1\">[*]</a>") == 2
|
||||
doAssert output3.count("href=\"#footnotesym-2\">[**]</a>") == 2
|
||||
|
|
@ -1047,7 +1047,7 @@ Test1
|
|||
|
||||
Ref. [#note]_ and [#]_ and [#]_.
|
||||
"""
|
||||
let output4 = input4.toHtml
|
||||
let output4 = input4.toHtml(preferRst)
|
||||
doAssert ">[-1]" notin output1
|
||||
let order = @[
|
||||
"footnote-3", "[3]", "Manual1.",
|
||||
|
|
@ -1072,7 +1072,7 @@ Test1
|
|||
Ref. [#note]_
|
||||
"""
|
||||
var error5 = new string
|
||||
let output5 = input5.toHtml(error=error5)
|
||||
let output5 = input5.toHtml(preferRst, error=error5)
|
||||
check(error5[] == "input(1, 1) Error: mismatch in number of footnotes " &
|
||||
"and their refs: 1 (lines 2) != 0 (lines ) for auto-numbered " &
|
||||
"footnotes")
|
||||
|
|
@ -1086,7 +1086,7 @@ Test1
|
|||
Ref. [*]_
|
||||
"""
|
||||
var error6 = new string
|
||||
let output6 = input6.toHtml(error=error6)
|
||||
let output6 = input6.toHtml(preferRst, error=error6)
|
||||
check(error6[] == "input(1, 1) Error: mismatch in number of footnotes " &
|
||||
"and their refs: 1 (lines 3) != 2 (lines 2, 6) for auto-symbol " &
|
||||
"footnotes")
|
||||
|
|
@ -1096,7 +1096,7 @@ Test1
|
|||
|
||||
Ref. [some:citation-2020]_.
|
||||
"""
|
||||
let output7 = input7.toHtml
|
||||
let output7 = input7.toHtml(preferRst)
|
||||
doAssert output7.count("href=\"#citation-somecoloncitationminus2020\"") == 2
|
||||
doAssert output7.count("[Some:CITATION-2020]") == 1
|
||||
doAssert output7.count("[some:citation-2020]") == 1
|
||||
|
|
@ -1109,7 +1109,7 @@ Test1
|
|||
Ref. [som]_.
|
||||
"""
|
||||
var warnings8 = new seq[string]
|
||||
let output8 = input8.toHtml(warnings=warnings8)
|
||||
let output8 = input8.toHtml(preferRst, warnings=warnings8)
|
||||
check(warnings8[] == @["input(3, 7) Warning: broken link 'citation-som'"])
|
||||
|
||||
# check that footnote group does not break parsing of other directives:
|
||||
|
|
@ -1145,7 +1145,7 @@ Test1
|
|||
|
||||
.. [Third] Citation.
|
||||
"""
|
||||
let output10 = input10.toHtml
|
||||
let output10 = input10.toHtml(preferRst)
|
||||
doAssert output10.count("<hr class=\"footnote\">" &
|
||||
"<div class=\"footnote-group\">") == 3
|
||||
doAssert output10.count("<div class=\"footnote-label\">") == 3
|
||||
|
|
@ -1165,7 +1165,7 @@ Test1
|
|||
.. [#] Body3
|
||||
.. [2] Body2.
|
||||
"""
|
||||
let output12 = input12.toHtml
|
||||
let output12 = input12.toHtml(preferRst)
|
||||
let orderAuto = @[
|
||||
"#footnoteauto-1", "[1]",
|
||||
"#footnoteauto-2", "[3]",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue