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
|
|
@ -49,7 +49,10 @@ type
|
|||
rnCitation, # similar to footnote, so use rnFootnote instead
|
||||
rnFootnoteGroup, # footnote group - exists for a purely stylistic
|
||||
# reason: to display a few footnotes as 1 block
|
||||
rnStandaloneHyperlink, rnHyperlink, rnRef, rnInternalRef, rnFootnoteRef,
|
||||
rnStandaloneHyperlink, rnHyperlink,
|
||||
rnRstRef, # RST reference like `section name`_
|
||||
rnPandocRef, # Pandoc Markdown reference like [section name]
|
||||
rnInternalRef, rnFootnoteRef,
|
||||
rnNimdocRef, # reference to automatically generated Nim symbol
|
||||
rnDirective, # a general directive
|
||||
rnDirArg, # a directive argument (for some directives).
|
||||
|
|
@ -110,7 +113,7 @@ type
|
|||
## auto-numbered ones without a label)
|
||||
of rnMarkdownBlockQuoteItem:
|
||||
quotationDepth*: int ## number of characters in line prefix
|
||||
of rnRef, rnSubstitutionReferences,
|
||||
of rnRstRef, rnPandocRef, rnSubstitutionReferences,
|
||||
rnInterpretedText, rnField, rnInlineCode, rnCodeBlock, rnFootnoteRef:
|
||||
info*: TLineInfo ## To have line/column info for warnings at
|
||||
## nodes that are post-processed after parsing
|
||||
|
|
@ -281,7 +284,7 @@ proc renderRstToRst(d: var RenderContext, n: PRstNode, result: var string) =
|
|||
inc(d.indent, 2)
|
||||
renderRstSons(d, n, result)
|
||||
dec(d.indent, 2)
|
||||
of rnRef:
|
||||
of rnRstRef:
|
||||
result.add("`")
|
||||
renderRstSons(d, n, result)
|
||||
result.add("`_")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue