Nim-flavored Markdown and reStructuredText (original) (raw)

Source Edit

Author: Andrey Makarov
Version: 2.3.1

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.

Command line usage

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

Basic markup

If you are new to Markdown/RST please consider reading the following:

  1. Markdown Basic Syntax
  2. a long specification of Markdown: CommonMark Spec
  3. a short quick introduction to RST
  4. an RST reference: a comprehensive cheatsheet for RST
  5. a more formal 50-page RST specification.

Features

A large subset is implemented with some limitations and additional Nim-specific features.

Supported common RST/Markdown features:

RST mode only features

Markdown-specific features

echo "ok"  

Additional Nim-specific features


**Note:**By default Nim has

roSupportMarkdown

and

roSupportRawDirective

turned on.

**Warning:**Using Nim-specific features can cause other Markdown and RST implementations to fail on your document.

Referencing

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:

  1. the anchors are usually mangled (e.g. spaces substituted to minus signs, etc).
  2. manual usage of anchors is not checked, so it's easy to get broken links inside your project if e.g. spelling has changed for a heading or you use a wrong relative path to your document.

That's why Nim implementation has syntax for using original labels for referencing. Such referencing can be either local/internal or external:

Markup local referencing

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_

Markup external referencing

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
nim md2html file2.md

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
nim md2html --index:only file2.md
nim md2html file1.md
nim md2html file2.md

and then one can freely reference any objects as if these 2 documents are actually 1 file.

Other

Idiosyncrasies

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:

  1. Markdown-like mode which is enabled by roPreferMarkdown option (turned on by default).
    **Note:**RST features like directives are still turned on
  2. Compatibility mode which is RST rules.

**Note:**in both modes the parser interpretes text between single backticks (code) identically: backslash does not escape; the only exception:

\

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

**Attention:**We don't support some obviously poor design choices of Markdown (or RST).

Limitations

Additional resources