Both Markdown (md) and reStructuredText (RST) are markup languages whose goal is to typeset texts with complex structure, formatting and references using simple plaintext representation.
Usage (to convert Markdown into HTML):
nim md2html markdown_rst.md
Output:
You're reading it!
The md2tex command is invoked identically to md2html, but outputs a .tex file instead of .html.
These tools embedded into Nim compiler; the compiler can output the result to HTML [1] or Latex [2].
Full list of supported commands:
| command | runs on... | input format | output format |
|---|---|---|---|
nim md2html |
standalone md files | .md |
.html HTML |
nim md2tex |
same | same |
.tex LaTeX |
nim rst2html |
standalone rst files | .rst |
.html HTML |
nim rst2tex |
same | same |
.tex LaTeX |
nim doc |
documentation comments | .nim |
.html HTML |
nim doc2tex |
same | same |
.tex LaTeX |
nim jsondoc |
same | same |
.json JSON |
If you are new to Markdown/RST please consider reading the following:
A large subset is implemented with some limitations and additional Nim-specific features.
Supported common RST/Markdown features:
image, figure for including images and videoscodecontents (table of contents), container, raw
includereplace and image
inline literals, hyperlink references (including embedded URI), substitution references, standalone hyperlinks, internal links (inline and outline):literal:, :strong:, emphasis, :sub:/:subscript:, :sup:/:superscript: (see RST roles list for description).::
test or number-lines) but with a one-line syntax like this:```nim test number-lines=10 echo "ok" ```
[...](...)
[...], see Referencing for description[^10] (manually numbered) and [^someName] (auto-numbered with a label)1 as auto-enumerator in enumerated lists like RST # (auto-enumerator 1 can not be used with # in the same list)code-block [3], title, index [3]
:nim: (default), :c: (C programming language), :python:, :yaml:, :java:, :cpp: (C++), :csharp (C#). That is every language that highlite supports. They turn on appropriate syntax highlighting in inline code.:nim:, for *.rst it's currently :literal:.:tok:, a role for highlighting of programming language tokens:idx: role for `interpreted text` to include the link to this text into an index (example: Nim index).// in option lists serves as a prefix for any option that starts from a word (without any leading symbols like -, --, /)://compile compile the project //doc generate documentation
Here the dummy // will disappear, while options compile and doc will be left in the final document.
roSupportMarkdown and roSupportRawDirective turned on.To be able to copy and share links Nim generates anchors for all main document elements:
But direct use of those anchors have 2 problems:
That's why Nim implementation has syntax for using original labels for referencing. Such referencing can be either local/internal or external:
There are 2 syntax option available for referencing to objects inside any given file, e.g. for headlines:
Markdown RST Some headline Some headline ============= ============= Ref. [Some headline] Ref. `Some headline`_
The syntax is the same as for local referencing, but the anchors are saved in .idx files, so one needs to generate them beforehand, and they should be loaded by an .. importdoc:: directive. E.g. if we want to reference section "Some headline" in file1.md from file2.md, then file2.md may look like:
.. importdoc:: file1.md Ref. [Some headline]
nim md2html --index:only file1.md # creates ``htmldocs/file1.idx`` nim md2html file2.md # creates ``htmldocs/file2.html``
To allow cross-references between any files in any order (especially, if circular references are present), it's strongly recommended to make a run for creating all the indexes first:
nim md2html --index:only file1.md # creates ``htmldocs/file1.idx`` nim md2html --index:only file2.md # creates ``htmldocs/file2.idx`` nim md2html file1.md # creates ``htmldocs/file1.html`` nim md2html file2.md # creates ``htmldocs/file2.html``
and then one can freely reference any objects as if these 2 documents are actually 1 file.
Currently we do not aim at 100% Markdown or RST compatibility in inline markup recognition rules because that would provide very little user value. This parser has 2 modes for inline markup:
roPreferMarkdown option (turned on by default).\ folowed by ` does escape so that we can always input a single backtick ` in inline code. However that makes impossible to input code with \ at the end in single backticks, one must use double backticks:`\` -- WRONG ``\`` -- GOOD So single backticks can always be input: `\`` will turn to ` code
>>> foo > bar >>baz
is a single 3rd-level quote foo bar baz in original Markdown, while in Nim we naturally see it as 3rd-level quote foo + 1st level bar + 2nd level baz:
foo
bar
baz
parsed-literal, sidebar, topic, math, rubric, epigraph, highlights, pull-quote, compound, table, csv-table, list-table, section-numbering, header, footer, meta, classrole directives and no custom interpreted text rolesnim doc command and idiosyncrasies of documentation markup in .nim files and Nim programming language projects.
© 2006–2024 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/markdown_rst.html