Markdown code blocks part 4 (#20189)
No logic was added, just 8 more files have been migrated.
This commit is contained in:
parent
8155837cde
commit
713f39083e
9 changed files with 365 additions and 341 deletions
|
|
@ -18,11 +18,11 @@ General Guidelines
|
|||
* (debatable) In nim sources, for links, prefer ``[link text](link.html)`` to `\`link text<link.html>\`_`:code:
|
||||
since the syntax is simpler and markdown is more common (likewise, `nim rst2html`:cmd: also supports it in ``rst`` files).
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc someproc*(s: string, foo: int) =
|
||||
## Use single backticks for inline code, e.g.: `s` or `someExpr(true)`.
|
||||
## Use a backlash to follow with alphanumeric char: `int8`\s are great.
|
||||
```
|
||||
|
||||
|
||||
Module-level documentation
|
||||
|
|
@ -32,23 +32,24 @@ Documentation of a module is placed at the top of the module itself. Each line o
|
|||
Sometimes `##[ multiline docs containing code ]##` is preferable, see ``lib/pure/times.nim``.
|
||||
Code samples are encouraged, and should follow the general RST syntax:
|
||||
|
||||
.. code-block:: Nim
|
||||
|
||||
````Nim
|
||||
## The `universe` module computes the answer to life, the universe, and everything.
|
||||
##
|
||||
## .. code-block::
|
||||
## doAssert computeAnswerString() == 42
|
||||
## ```
|
||||
## doAssert computeAnswerString() == 42
|
||||
## ```
|
||||
````
|
||||
|
||||
|
||||
Within this top-level comment, you can indicate the authorship and copyright of the code, which will be featured in the produced documentation.
|
||||
|
||||
.. code-block:: Nim
|
||||
|
||||
```Nim
|
||||
## This is the best module ever. It provides answers to everything!
|
||||
##
|
||||
## :Author: Steve McQueen
|
||||
## :Copyright: 1965
|
||||
##
|
||||
```
|
||||
|
||||
Leave a space between the last line of top-level documentation and the beginning of Nim code (the imports, etc.).
|
||||
|
||||
|
|
@ -57,28 +58,29 @@ Procs, Templates, Macros, Converters, and Iterators
|
|||
|
||||
The documentation of a procedure should begin with a capital letter and should be in present tense. Variables referenced in the documentation should be surrounded by single tick marks:
|
||||
|
||||
.. code-block:: Nim
|
||||
|
||||
```Nim
|
||||
proc example1*(x: int) =
|
||||
## Prints the value of `x`.
|
||||
echo x
|
||||
```
|
||||
|
||||
Whenever an example of usage would be helpful to the user, you should include one within the documentation in RST format as below.
|
||||
|
||||
.. code-block:: Nim
|
||||
|
||||
````Nim
|
||||
proc addThree*(x, y, z: int8): int =
|
||||
## Adds three `int8` values, treating them as unsigned and
|
||||
## truncating the result.
|
||||
##
|
||||
## .. code-block::
|
||||
## # things that aren't suitable for a `runnableExamples` go in code-block:
|
||||
## echo execCmdEx("git pull")
|
||||
## drawOnScreen()
|
||||
## ```
|
||||
## # things that aren't suitable for a `runnableExamples` go in code-block:
|
||||
## echo execCmdEx("git pull")
|
||||
## drawOnScreen()
|
||||
## ```
|
||||
runnableExamples:
|
||||
# `runnableExamples` is usually preferred to ``code-block``, when possible.
|
||||
doAssert addThree(3, 125, 6) == -122
|
||||
result = x +% y +% z
|
||||
````
|
||||
|
||||
The command `nim doc`:cmd: will then correctly syntax highlight the Nim code within the documentation.
|
||||
|
||||
|
|
@ -87,8 +89,7 @@ Types
|
|||
|
||||
Exported types should also be documented. This documentation can also contain code samples, but those are better placed with the functions to which they refer.
|
||||
|
||||
.. code-block:: Nim
|
||||
|
||||
```Nim
|
||||
type
|
||||
NamedQueue*[T] = object ## Provides a linked data structure with names
|
||||
## throughout. It is named for convenience. I'm making
|
||||
|
|
@ -96,12 +97,12 @@ Exported types should also be documented. This documentation can also contain co
|
|||
name*: string ## The name of the item
|
||||
val*: T ## Its value
|
||||
next*: ref NamedQueue[T] ## The next item in the queue
|
||||
```
|
||||
|
||||
|
||||
You have some flexibility when placing the documentation:
|
||||
|
||||
.. code-block:: Nim
|
||||
|
||||
```Nim
|
||||
type
|
||||
NamedQueue*[T] = object
|
||||
## Provides a linked data structure with names
|
||||
|
|
@ -110,11 +111,11 @@ You have some flexibility when placing the documentation:
|
|||
name*: string ## The name of the item
|
||||
val*: T ## Its value
|
||||
next*: ref NamedQueue[T] ## The next item in the queue
|
||||
```
|
||||
|
||||
Make sure to place the documentation beside or within the object.
|
||||
|
||||
.. code-block:: Nim
|
||||
|
||||
```Nim
|
||||
type
|
||||
## Bad: this documentation disappears because it annotates the `type` keyword
|
||||
## above, not `NamedQueue`.
|
||||
|
|
@ -123,14 +124,14 @@ Make sure to place the documentation beside or within the object.
|
|||
## is not what we want.
|
||||
val*: T ## Its value
|
||||
next*: ref NamedQueue[T] ## The next item in the queue
|
||||
```
|
||||
|
||||
Var, Let, and Const
|
||||
-------------------
|
||||
|
||||
When declaring module-wide constants and values, documentation is encouraged. The placement of doc comments is similar to the `type` sections.
|
||||
|
||||
.. code-block:: Nim
|
||||
|
||||
```Nim
|
||||
const
|
||||
X* = 42 ## An awesome number.
|
||||
SpreadArray* = [
|
||||
|
|
@ -138,25 +139,26 @@ When declaring module-wide constants and values, documentation is encouraged. Th
|
|||
[2,3,1],
|
||||
[3,1,2],
|
||||
] ## Doc comment for `SpreadArray`.
|
||||
```
|
||||
|
||||
Placement of comments in other areas is usually allowed, but will not become part of the documentation output and should therefore be prefaced by a single hash (`#`).
|
||||
|
||||
.. code-block:: Nim
|
||||
|
||||
```Nim
|
||||
const
|
||||
BadMathVals* = [
|
||||
3.14, # pi
|
||||
2.72, # e
|
||||
0.58, # gamma
|
||||
] ## A bunch of badly rounded values.
|
||||
```
|
||||
|
||||
Nim supports Unicode in comments, so the above can be replaced with the following:
|
||||
|
||||
.. code-block:: Nim
|
||||
|
||||
```Nim
|
||||
const
|
||||
BadMathVals* = [
|
||||
3.14, # π
|
||||
2.72, # e
|
||||
0.58, # γ
|
||||
] ## A bunch of badly rounded values (including π!).
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue