Debian Codegraph @

docs/extensions/sane_lists.md

raw
1 title: Sane Lists Extension
2
3 Sane Lists
4 ==========
5
6 Summary
7 -------
8
9 The Sane Lists extension alters the behavior of the Markdown List syntax
10 to be less surprising.
11
12 This extension is included in the standard Markdown library.
13
14 !!! Note
15
16 This extension is in __maintenance mode__. We will continue to fix bugs
17 and keep it up-to-date with the core parser, but no new features or
18 changes in behavior will be made. If you need a feature that this
19 extension does not offer, then you have three options (1) find an
20 existing [third-party extension] which meets your needs, (2) [build your
21 own extension], or (3) fork this extension (pursuant to its licensing
22 requirements) and maintain it as a third-party extension.
23
24 [third-party extension]: index.md#third-party-extensions
25 [build your own extension]: api.md
26
27 Syntax
28 ------
29
30 Sane Lists do not allow the mixing of list types. In other words, an ordered
31 list will not continue when an unordered list item is encountered and
32 vice versa. For example:
33
34 ```md
35 1. Ordered item 1
36 2. Ordered item 2
37
38 * Unordered item 1
39 * Unordered item 2
40 ```
41
42 will result in the following output:
43
44 ```html
45 <ol>
46 <li>Ordered item 1</li>
47 <li>Ordered item 2</li>
48 </ol>
49
50 <ul>
51 <li>Unordered item 1</li>
52 <li>Unordered item 2</li>
53 </ul>
54 ```
55
56 Whereas the default Markdown behavior would be to generate an unordered list.
57
58 Note that, unlike the default Markdown behavior, if a blank line is not
59 included between list items, the different list type is ignored completely.
60 This corresponds to the behavior of paragraphs. For example:
61
62 ```md
63 A Paragraph.
64 * Not a list item.
65
66 1. Ordered list item.
67 * Not a separate list item.
68 ```
69
70 With this extension the above will result in the following output:
71
72 ```html
73 <p>A Paragraph.
74 * Not a list item.</p>
75
76 <ol>
77 <li>Ordered list item.
78 * Not a separate list item.</li>
79 </ol>
80 ```
81
82 Sane lists also recognize the number used in ordered lists. Given the following
83 list:
84
85 ```md
86 4. Apples
87 5. Oranges
88 6. Pears
89 ```
90
91 By default markdown will ignore the fact that the first line started
92 with item number "4" and the HTML list will start with a number "1".
93 This extension will result in the following HTML output:
94
95 ```html
96 <ol start="4">
97 <li>Apples</li>
98 <li>Oranges</li>
99 <li>Pears</li>
100 </ol>
101 ```
102
103 In all other ways, Sane Lists should behave as normal Markdown lists.
104
105 Usage
106 -----
107
108 See [Extensions](index.md) for general extension usage. Use `sane_lists` as the
109 name of the extension.
110
111 This extension does not accept any special configuration options.
112
113 A trivial example:
114
115 ```python
116 markdown.markdown(some_text, extensions=['sane_lists'])
117 ```