Skip to content

Commit 1bdb83c

Browse files
committed
Implement Pandoc Markdown concise link extension
This implements nim-lang#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.
1 parent b931e74 commit 1bdb83c

File tree

23 files changed

+318
-144
lines changed

23 files changed

+318
-144
lines changed

doc/basicopt.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Command:
66
//compile, c compile project with default code generator (C)
7-
//r compile to $nimcache/projname, run with [arguments]
7+
//r compile to $nimcache/projname, run with `arguments`
88
using backend specified by `--backend` (default: c)
99
//doc generate the documentation for inputfile for
1010
backend specified by `--backend` (default: c)

doc/contributing.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ To avoid accidental highlighting follow this rule in ``*.nim`` files:
336336

337337
.. Note:: ``*.rst`` files have ``:literal:`` as their default role.
338338
So for them the rule above is only applicable if the ``:nim:`` role
339-
is set up manually as the default [*]_::
339+
is set up manually as the default \[*]::
340340

341341
.. role:: nim(code)
342342
:language: nim
@@ -345,7 +345,7 @@ To avoid accidental highlighting follow this rule in ``*.nim`` files:
345345
The first 2 lines are for other RST implementations,
346346
including Github one.
347347

348-
.. [*] this is fulfilled when ``doc/rstcommon.rst`` is included.
348+
\[*] this is fulfilled when ``doc/rstcommon.rst`` is included.
349349

350350
Best practices
351351
==============
@@ -431,7 +431,7 @@ including prepending location info, writing to log files, etc.).
431431
```
432432

433433
.. _use_Option:
434-
[Ongoing debate] Consider using Option instead of return bool + var argument,
434+
(Ongoing debate) Consider using Option instead of return bool + var argument,
435435
unless stack allocation is needed (e.g. for efficiency).
436436

437437
```nim

doc/docgen.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ underscore `_` to a *link text*.
245245
Link text is either one word or a group of words enclosed by backticks `\``
246246
(for a one word case backticks are usually omitted).
247247
Link text will be displayed *as is* while *link target* will be set to
248-
the anchor [*]_ of Nim symbol that corresponds to link text.
248+
the anchor \[*] of Nim symbol that corresponds to link text.
249249

250-
.. [*] anchors' format is described in `HTML anchor generation`_ section below.
250+
[*] anchors' format is described in `HTML anchor generation`_ section below.
251251

252252
If you have a constant:
253253

doc/idetools.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ symbol for which idetools returns valid output.
239239
skConst
240240
-------
241241

242-
| **Third column**: module + [n scope nesting] + const name.
242+
| **Third column**: module + \[n scope nesting] + const name.
243243
| **Fourth column**: the type of the const value.
244244
| **Docstring**: always the empty string.
245245

@@ -254,7 +254,7 @@ skConst
254254
skEnumField
255255
-----------
256256

257-
| **Third column**: module + [n scope nesting] + enum type + enum field name.
257+
| **Third column**: module + \[n scope nesting] + enum type + enum field name.
258258
| **Fourth column**: enum type grouping other enum fields.
259259
| **Docstring**: always the empty string.
260260

@@ -269,7 +269,7 @@ skEnumField
269269
skForVar
270270
--------
271271

272-
| **Third column**: module + [n scope nesting] + var name.
272+
| **Third column**: module + \[n scope nesting] + var name.
273273
| **Fourth column**: type of the var.
274274
| **Docstring**: always the empty string.
275275

@@ -291,7 +291,7 @@ defined, since at that point in the file the parser hasn't processed
291291
the full line yet. The signature will be returned complete in
292292
posterior instances of the iterator.
293293

294-
| **Third column**: module + [n scope nesting] + iterator name.
294+
| **Third column**: module + \[n scope nesting] + iterator name.
295295
| **Fourth column**: signature of the iterator including return type.
296296
| **Docstring**: docstring if available.
297297

@@ -308,7 +308,7 @@ posterior instances of the iterator.
308308
skLabel
309309
-------
310310

311-
| **Third column**: module + [n scope nesting] + name.
311+
| **Third column**: module + \[n scope nesting] + name.
312312
| **Fourth column**: always the empty string.
313313
| **Docstring**: always the empty string.
314314

@@ -325,7 +325,7 @@ skLabel
325325
skLet
326326
-----
327327

328-
| **Third column**: module + [n scope nesting] + let name.
328+
| **Third column**: module + \[n scope nesting] + let name.
329329
| **Fourth column**: the type of the let variable.
330330
| **Docstring**: always the empty string.
331331

@@ -346,7 +346,7 @@ defined, since at that point in the file the parser hasn't processed
346346
the full line yet. The signature will be returned complete in
347347
posterior instances of the macro.
348348

349-
| **Third column**: module + [n scope nesting] + macro name.
349+
| **Third column**: module + \[n scope nesting] + macro name.
350350
| **Fourth column**: signature of the macro including return type.
351351
| **Docstring**: docstring if available.
352352

@@ -384,7 +384,7 @@ Note that at the moment the word `proc` is returned for the
384384
signature of the found method instead of the expected `method`.
385385
This may change in the future.
386386

387-
| **Third column**: module + [n scope nesting] + method name.
387+
| **Third column**: module + \[n scope nesting] + method name.
388388
| **Fourth column**: signature of the method including return type.
389389
| **Docstring**: docstring if available.
390390

@@ -402,7 +402,7 @@ This may change in the future.
402402
skParam
403403
-------
404404

405-
| **Third column**: module + [n scope nesting] + param name.
405+
| **Third column**: module + \[n scope nesting] + param name.
406406
| **Fourth column**: the type of the parameter.
407407
| **Docstring**: always the empty string.
408408

@@ -427,7 +427,7 @@ While at the language level a proc is differentiated from others
427427
by the parameters and return value, the signature of the proc
428428
returned by idetools returns also the pragmas for the proc.
429429

430-
| **Third column**: module + [n scope nesting] + proc name.
430+
| **Third column**: module + \[n scope nesting] + proc name.
431431
| **Fourth column**: signature of the proc including return type.
432432
| **Docstring**: docstring if available.
433433

@@ -446,7 +446,7 @@ returned by idetools returns also the pragmas for the proc.
446446
skResult
447447
--------
448448

449-
| **Third column**: module + [n scope nesting] + result.
449+
| **Third column**: module + \[n scope nesting] + result.
450450
| **Fourth column**: the type of the result.
451451
| **Docstring**: always the empty string.
452452

@@ -467,7 +467,7 @@ defined, since at that point in the file the parser hasn't processed
467467
the full line yet. The signature will be returned complete in
468468
posterior instances of the template.
469469

470-
| **Third column**: module + [n scope nesting] + template name.
470+
| **Third column**: module + \[n scope nesting] + template name.
471471
| **Fourth column**: signature of the template including return type.
472472
| **Docstring**: docstring if available.
473473

@@ -496,7 +496,7 @@ posterior instances of the template.
496496
skType
497497
------
498498

499-
| **Third column**: module + [n scope nesting] + type name.
499+
| **Third column**: module + \[n scope nesting] + type name.
500500
| **Fourth column**: the type.
501501
| **Docstring**: always the empty string.
502502

@@ -512,7 +512,7 @@ skType
512512
skVar
513513
-----
514514

515-
| **Third column**: module + [n scope nesting] + var name.
515+
| **Third column**: module + \[n scope nesting] + var name.
516516
| **Fourth column**: the type of the var.
517517
| **Docstring**: always the empty string.
518518

doc/intern.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ Coding Guidelines
328328
* Max line length is 100 characters.
329329
* Provide spaces around binary operators if that enhances readability.
330330
* Use a space after a colon, but not before it.
331-
* [deprecated] Start types with a capital `T`, unless they are
331+
* (deprecated) Start types with a capital `T`, unless they are
332332
pointers/references which start with `P`.
333333
* Prefer `import package`:nim: over `from package import symbol`:nim:.
334334

doc/manual.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -2862,11 +2862,11 @@ ref or pointer type nil
28622862
procedural type nil
28632863
sequence `@[]`
28642864
string `""`
2865-
tuple[x: A, y: B, ...] (default(A), default(B), ...)
2865+
`tuple[x: A, y: B, ...]` (default(A), default(B), ...)
28662866
(analogous for objects)
2867-
array[0..., T] [default(T), ...]
2868-
range[T] default(T); this may be out of the valid range
2869-
T = enum cast[T]\(0); this may be an invalid value
2867+
`array[0..., T]` `[default(T), ...]`
2868+
`range[T]` default(T); this may be out of the valid range
2869+
T = enum `cast[T](0)`; this may be an invalid value
28702870
============================ ==============================================
28712871

28722872

lib/core/macros.nim

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ template `^^`(n: NimNode, i: untyped): untyped =
182182

183183
proc `[]`*[T, U: Ordinal](n: NimNode, x: HSlice[T, U]): seq[NimNode] =
184184
## Slice operation for NimNode.
185-
## Returns a seq of child of `n` who inclusive range [n[x.a], n[x.b]].
185+
## Returns a seq of child of `n` who inclusive range `[n[x.a], n[x.b]]`.
186186
let xa = n ^^ x.a
187187
let L = (n ^^ x.b) - xa + 1
188188
result = newSeq[NimNode](L)

lib/impure/db_mysql.nim

+3-3
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ iterator fastRows*(db: DbConn, query: SqlQuery,
180180
## if you require **ALL** the rows.
181181
##
182182
## Breaking the fastRows() iterator during a loop will cause the next
183-
## database query to raise an [EDb] exception `Commands out of sync`.
183+
## database query to raise an `EDb` exception `Commands out of sync`.
184184
rawExec(db, query, args)
185185
var sqlres = mysql.useResult(PMySQL db)
186186
if sqlres != nil:
@@ -203,7 +203,7 @@ iterator instantRows*(db: DbConn, query: SqlQuery,
203203
args: varargs[string, `$`]): InstantRow
204204
{.tags: [ReadDbEffect].} =
205205
## Same as fastRows but returns a handle that can be used to get column text
206-
## on demand using []. Returned handle is valid only within the iterator body.
206+
## on demand using `[]`. Returned handle is valid only within the iterator body.
207207
rawExec(db, query, args)
208208
var sqlres = mysql.useResult(PMySQL db)
209209
if sqlres != nil:
@@ -283,7 +283,7 @@ proc setColumnInfo(columns: var DbColumns; res: PRES; L: int) =
283283
iterator instantRows*(db: DbConn; columns: var DbColumns; query: SqlQuery;
284284
args: varargs[string, `$`]): InstantRow =
285285
## Same as fastRows but returns a handle that can be used to get column text
286-
## on demand using []. Returned handle is valid only within the iterator body.
286+
## on demand using `[]`. Returned handle is valid only within the iterator body.
287287
rawExec(db, query, args)
288288
var sqlres = mysql.useResult(PMySQL db)
289289
if sqlres != nil:

lib/impure/db_odbc.nim

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ proc dbError*(db: var DbConn) {.
168168
raise e
169169

170170
proc sqlCheck(db: var DbConn, resVal: TSqlSmallInt) {.raises: [DbError]} =
171-
## Wrapper that raises [EDb] if `resVal` is neither SQL_SUCCESS or SQL_NO_DATA
171+
## Wrapper that raises `EDb` if `resVal` is neither SQL_SUCCESS or SQL_NO_DATA
172172
if resVal notIn [SQL_SUCCESS, SQL_NO_DATA]: dbError(db)
173173

174174
proc sqlGetDBMS(db: var DbConn): string {.
@@ -304,7 +304,7 @@ iterator instantRows*(db: var DbConn, query: SqlQuery,
304304
args: varargs[string, `$`]): InstantRow
305305
{.tags: [ReadDbEffect, WriteDbEffect].} =
306306
## Same as fastRows but returns a handle that can be used to get column text
307-
## on demand using []. Returned handle is valid only within the iterator body.
307+
## on demand using `[]`. Returned handle is valid only within the iterator body.
308308
var
309309
rowRes: Row = @[]
310310
sz: TSqlLen = 0

lib/impure/db_postgres.nim

+2-2
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,15 @@ iterator instantRows*(db: DbConn, query: SqlQuery,
271271
args: varargs[string, `$`]): InstantRow
272272
{.tags: [ReadDbEffect].} =
273273
## same as fastRows but returns a handle that can be used to get column text
274-
## on demand using []. Returned handle is valid only within iterator body.
274+
## on demand using `[]`. Returned handle is valid only within iterator body.
275275
setupSingeRowQuery(db, query, args)
276276
fetchinstantRows(db)
277277

278278
iterator instantRows*(db: DbConn, stmtName: SqlPrepared,
279279
args: varargs[string, `$`]): InstantRow
280280
{.tags: [ReadDbEffect].} =
281281
## same as fastRows but returns a handle that can be used to get column text
282-
## on demand using []. Returned handle is valid only within iterator body.
282+
## on demand using `[]`. Returned handle is valid only within iterator body.
283283
setupSingeRowQuery(db, stmtName, args)
284284
fetchinstantRows(db)
285285

lib/packages/docutils/dochelpers.nim

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ proc toLangSymbol*(linkText: PRstNode): LangSymbol =
8282
##
8383
## This proc should be kept in sync with the `renderTypes` proc from
8484
## ``compiler/typesrenderer.nim``.
85-
assert linkText.kind in {rnRef, rnInner}
85+
assert linkText.kind in {rnRstRef, rnInner}
8686

8787
const NimDefs = ["proc", "func", "macro", "method", "iterator",
8888
"template", "converter", "const", "type", "var",

0 commit comments

Comments
 (0)