File: markdown.rst

package info (click to toggle)
sphinx-argparse 0.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 288 kB
  • sloc: python: 1,514; makefile: 133
file content (116 lines) | stat: -rw-r--r-- 2,857 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
Markdown
========

As of version 0.2.0, markdown (rather than only reStructuredText) can be included inside directives as nested content.
While markdown is much easier to write, please note that it is also less powerful.
An example is below:

.. code:: rst

   .. argparse::
      :filename: ../test/sample.py
      :func: parser
      :prog: sample
      :markdown:

      Header 1
      ========

      [I'm a link to google](http://www.google.com)

      ## Sub-heading

      ```
      This
       is
        a
        fenced
       code
      block
      ```

The above example renders as follows:

.. argparse::
    :filename: ../test/sample.py
    :func: parser
    :prog: sample
    :markdown:

    A random paragraph

    Heading 1
    =========

    [I'm a link to google](http://www.google.com)

    ## Sub heading

    ```
    This
     is
      a
      fenced
     code
    block
    ```

The `CommonMark-py <https://github.com/rtfd/CommonMark-py>`__ is used internally to parse Markdown.
Consequently, only Markdown supported by CommonMark-py will be rendered.

You must explicitly use the ``:markdown:`` flag, otherwise all content inside directives will be parsed as reStructuredText.

A note on headers
-----------------

If the Markdown you nest includes headings, then the first one **MUST** be level 1.
Subsequent headings can be at `lower levels <http://daringfireball.net/projects/markdown/syntax#header>`__ and then rendered correctly.

Hard line breaks
----------------

Sphinx strips white-space from the end of lines prior to handing it to this package.
Because of that, hard line breaks can not currently be rendered.

Replacing/appending/prepending content
--------------------------------------

When markdown is used as nested content, it's not possible to create dictionary entries like in reStructuredText to `modify program option descriptions <extend.html>`__.
This is because CommonMark-py does not support dictionary entries.

MarkDown in program descriptions and option help
------------------------------------------------

In addition to using MarkDown in nested content, one can also use MarkDown directly in program descriptions and option help messages.
For example:

.. code:: python

   import argparse

   def blah():
       parser = argparse.ArgumentParser(description="""
   ### Example of MarkDown inside programs

   [I'm a link](http://www.google.com)
   """)
       parser.add_argument('cmd', help='execute a `command`')
       return parser

To render this as MarkDown rather than reStructuredText, use the ``:markdownhelp:`` option:

.. code:: rst

    .. argparse::
        :filename: ../test/sample2.py
        :func: blah
        :prog: sample
        :markdownhelp:

This will then be rendered as:

.. argparse::
    :filename: ../test/sample2.py
    :func: blah
    :prog: sample
    :markdownhelp: