author | Arseniy Alekseyev <aalekseyev@janestreet.com> |
Wed, 11 Jan 2023 19:53:58 +0000 | |
changeset 49895 | 07792fd1837f |
parent 48875 | 6000f5b25c9b |
child 50304 | 805d4a462abb |
permissions | -rw-r--r-- |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39310
diff
changeset
|
1 |
from mercurial import minirst |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39310
diff
changeset
|
2 |
from mercurial.utils import stringutil |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39310
diff
changeset
|
3 |
|
9156
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
4 |
|
15263
70d7293c41d6
minirst: improve test harness
Matt Mackall <mpm@selenic.com>
parents:
15262
diff
changeset
|
5 |
def debugformat(text, form, **kwargs): |
39310
a2a5d4ad5276
minirst: make format() simply return a formatted text
Yuya Nishihara <yuya@tcha.org>
parents:
37942
diff
changeset
|
6 |
blocks, pruned = minirst.parse(text, **kwargs) |
37882
3d24f708f7b6
tests: port test-minirst.py to Python 3
Augie Fackler <augie@google.com>
parents:
37881
diff
changeset
|
7 |
if form == b'html': |
28752
6b2f9a4e2f97
py3: use print_function in test-minirst.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28751
diff
changeset
|
8 |
print("html format:") |
15263
70d7293c41d6
minirst: improve test harness
Matt Mackall <mpm@selenic.com>
parents:
15262
diff
changeset
|
9 |
out = minirst.format(text, style=form, **kwargs) |
70d7293c41d6
minirst: improve test harness
Matt Mackall <mpm@selenic.com>
parents:
15262
diff
changeset
|
10 |
else: |
28752
6b2f9a4e2f97
py3: use print_function in test-minirst.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28751
diff
changeset
|
11 |
print("%d column format:" % form) |
15263
70d7293c41d6
minirst: improve test harness
Matt Mackall <mpm@selenic.com>
parents:
15262
diff
changeset
|
12 |
out = minirst.format(text, width=form, **kwargs) |
70d7293c41d6
minirst: improve test harness
Matt Mackall <mpm@selenic.com>
parents:
15262
diff
changeset
|
13 |
|
28752
6b2f9a4e2f97
py3: use print_function in test-minirst.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28751
diff
changeset
|
14 |
print("-" * 70) |
39310
a2a5d4ad5276
minirst: make format() simply return a formatted text
Yuya Nishihara <yuya@tcha.org>
parents:
37942
diff
changeset
|
15 |
print(out[:-1].decode('utf8')) |
a2a5d4ad5276
minirst: make format() simply return a formatted text
Yuya Nishihara <yuya@tcha.org>
parents:
37942
diff
changeset
|
16 |
if kwargs.get('keep'): |
28752
6b2f9a4e2f97
py3: use print_function in test-minirst.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28751
diff
changeset
|
17 |
print("-" * 70) |
39310
a2a5d4ad5276
minirst: make format() simply return a formatted text
Yuya Nishihara <yuya@tcha.org>
parents:
37942
diff
changeset
|
18 |
print(stringutil.pprint(pruned).decode('utf8')) |
28752
6b2f9a4e2f97
py3: use print_function in test-minirst.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28751
diff
changeset
|
19 |
print("-" * 70) |
6b2f9a4e2f97
py3: use print_function in test-minirst.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28751
diff
changeset
|
20 |
print() |
9156
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
21 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39310
diff
changeset
|
22 |
|
15263
70d7293c41d6
minirst: improve test harness
Matt Mackall <mpm@selenic.com>
parents:
15262
diff
changeset
|
23 |
def debugformats(title, text, **kwargs): |
28752
6b2f9a4e2f97
py3: use print_function in test-minirst.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28751
diff
changeset
|
24 |
print("== %s ==" % title) |
15263
70d7293c41d6
minirst: improve test harness
Matt Mackall <mpm@selenic.com>
parents:
15262
diff
changeset
|
25 |
debugformat(text, 60, **kwargs) |
70d7293c41d6
minirst: improve test harness
Matt Mackall <mpm@selenic.com>
parents:
15262
diff
changeset
|
26 |
debugformat(text, 30, **kwargs) |
37882
3d24f708f7b6
tests: port test-minirst.py to Python 3
Augie Fackler <augie@google.com>
parents:
37881
diff
changeset
|
27 |
debugformat(text, b'html', **kwargs) |
15263
70d7293c41d6
minirst: improve test harness
Matt Mackall <mpm@selenic.com>
parents:
15262
diff
changeset
|
28 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39310
diff
changeset
|
29 |
|
36706
87b8fc4533ca
py3: add b'' prefixes in tests/test-minirst.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31130
diff
changeset
|
30 |
paragraphs = b""" |
9156
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
31 |
This is some text in the first paragraph. |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
32 |
|
9736
26d3ade60fa6
test-minirst: don't test on invalid reST input
Martin Geisler <mg@lazybytes.net>
parents:
9293
diff
changeset
|
33 |
A small indented paragraph. |
26d3ade60fa6
test-minirst: don't test on invalid reST input
Martin Geisler <mg@lazybytes.net>
parents:
9293
diff
changeset
|
34 |
It is followed by some lines |
26d3ade60fa6
test-minirst: don't test on invalid reST input
Martin Geisler <mg@lazybytes.net>
parents:
9293
diff
changeset
|
35 |
containing random whitespace. |
10289
987df17f85bb
test-minirst: hide trailing whitespace from check-code
Matt Mackall <mpm@selenic.com>
parents:
10065
diff
changeset
|
36 |
\n \n \nThe third and final paragraph. |
9156
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
37 |
""" |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
38 |
|
37882
3d24f708f7b6
tests: port test-minirst.py to Python 3
Augie Fackler <augie@google.com>
parents:
37881
diff
changeset
|
39 |
debugformats('paragraphs', paragraphs) |
9156
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
40 |
|
36706
87b8fc4533ca
py3: add b'' prefixes in tests/test-minirst.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31130
diff
changeset
|
41 |
definitions = b""" |
9156
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
42 |
A Term |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
43 |
Definition. The indented |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
44 |
lines make up the definition. |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
45 |
Another Term |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
46 |
Another definition. The final line in the |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
47 |
definition determines the indentation, so |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
48 |
this will be indented with four spaces. |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
49 |
|
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
50 |
A Nested/Indented Term |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
51 |
Definition. |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
52 |
""" |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
53 |
|
37882
3d24f708f7b6
tests: port test-minirst.py to Python 3
Augie Fackler <augie@google.com>
parents:
37881
diff
changeset
|
54 |
debugformats('definitions', definitions) |
9156
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
55 |
|
36706
87b8fc4533ca
py3: add b'' prefixes in tests/test-minirst.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31130
diff
changeset
|
56 |
literals = br""" |
9156
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
57 |
The fully minimized form is the most |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
58 |
convenient form:: |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
59 |
|
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
60 |
Hello |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
61 |
literal |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
62 |
world |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
63 |
|
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
64 |
In the partially minimized form a paragraph |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
65 |
simply ends with space-double-colon. :: |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
66 |
|
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
67 |
//////////////////////////////////////// |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
68 |
long un-wrapped line in a literal block |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
69 |
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
70 |
|
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
71 |
:: |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
72 |
|
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
73 |
This literal block is started with '::', |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
74 |
the so-called expanded form. The paragraph |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
75 |
with '::' disappears in the final output. |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
76 |
""" |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
77 |
|
37882
3d24f708f7b6
tests: port test-minirst.py to Python 3
Augie Fackler <augie@google.com>
parents:
37881
diff
changeset
|
78 |
debugformats('literals', literals) |
9156
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
79 |
|
36706
87b8fc4533ca
py3: add b'' prefixes in tests/test-minirst.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31130
diff
changeset
|
80 |
lists = b""" |
9156
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
81 |
- This is the first list item. |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
82 |
|
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
83 |
Second paragraph in the first list item. |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
84 |
|
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
85 |
- List items need not be separated |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
86 |
by a blank line. |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
87 |
- And will be rendered without |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
88 |
one in any case. |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
89 |
|
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
90 |
We can have indented lists: |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
91 |
|
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
92 |
- This is an indented list item |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
93 |
|
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
94 |
- Another indented list item:: |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
95 |
|
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
96 |
- A literal block in the middle |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
97 |
of an indented list. |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
98 |
|
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
99 |
(The above is not a list item since we are in the literal block.) |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
100 |
|
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
101 |
:: |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
102 |
|
9291
cd5b6a11b607
minirst: indent literal blocks with two spaces
Martin Geisler <mg@lazybytes.net>
parents:
9156
diff
changeset
|
103 |
Literal block with no indentation (apart from |
cd5b6a11b607
minirst: indent literal blocks with two spaces
Martin Geisler <mg@lazybytes.net>
parents:
9156
diff
changeset
|
104 |
the two spaces added to all literal blocks). |
9739
75cff8f12910
minirst: support enumerated lists
Martin Geisler <mg@lazybytes.net>
parents:
9736
diff
changeset
|
105 |
|
75cff8f12910
minirst: support enumerated lists
Martin Geisler <mg@lazybytes.net>
parents:
9736
diff
changeset
|
106 |
1. This is an enumerated list (first item). |
75cff8f12910
minirst: support enumerated lists
Martin Geisler <mg@lazybytes.net>
parents:
9736
diff
changeset
|
107 |
2. Continuing with the second item. |
75cff8f12910
minirst: support enumerated lists
Martin Geisler <mg@lazybytes.net>
parents:
9736
diff
changeset
|
108 |
|
75cff8f12910
minirst: support enumerated lists
Martin Geisler <mg@lazybytes.net>
parents:
9736
diff
changeset
|
109 |
(1) foo |
75cff8f12910
minirst: support enumerated lists
Martin Geisler <mg@lazybytes.net>
parents:
9736
diff
changeset
|
110 |
(2) bar |
75cff8f12910
minirst: support enumerated lists
Martin Geisler <mg@lazybytes.net>
parents:
9736
diff
changeset
|
111 |
|
75cff8f12910
minirst: support enumerated lists
Martin Geisler <mg@lazybytes.net>
parents:
9736
diff
changeset
|
112 |
1) Another |
75cff8f12910
minirst: support enumerated lists
Martin Geisler <mg@lazybytes.net>
parents:
9736
diff
changeset
|
113 |
2) List |
10447
e957cc7cbd14
minirst: support line blocks
Martin Geisler <mg@lazybytes.net>
parents:
10444
diff
changeset
|
114 |
|
e957cc7cbd14
minirst: support line blocks
Martin Geisler <mg@lazybytes.net>
parents:
10444
diff
changeset
|
115 |
Line blocks are also a form of list: |
e957cc7cbd14
minirst: support line blocks
Martin Geisler <mg@lazybytes.net>
parents:
10444
diff
changeset
|
116 |
|
e957cc7cbd14
minirst: support line blocks
Martin Geisler <mg@lazybytes.net>
parents:
10444
diff
changeset
|
117 |
| This is the first line. |
e957cc7cbd14
minirst: support line blocks
Martin Geisler <mg@lazybytes.net>
parents:
10444
diff
changeset
|
118 |
The line continues here. |
e957cc7cbd14
minirst: support line blocks
Martin Geisler <mg@lazybytes.net>
parents:
10444
diff
changeset
|
119 |
| This is the second line. |
31130
6582b3716ae0
minirst: detect bullet lists using asterisks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28840
diff
changeset
|
120 |
|
6582b3716ae0
minirst: detect bullet lists using asterisks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28840
diff
changeset
|
121 |
Bullet lists are also detected: |
6582b3716ae0
minirst: detect bullet lists using asterisks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28840
diff
changeset
|
122 |
|
6582b3716ae0
minirst: detect bullet lists using asterisks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28840
diff
changeset
|
123 |
* This is the first bullet |
6582b3716ae0
minirst: detect bullet lists using asterisks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28840
diff
changeset
|
124 |
* This is the second bullet |
6582b3716ae0
minirst: detect bullet lists using asterisks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28840
diff
changeset
|
125 |
It has 2 lines |
6582b3716ae0
minirst: detect bullet lists using asterisks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28840
diff
changeset
|
126 |
* This is the third bullet |
9156
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
127 |
""" |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
128 |
|
37882
3d24f708f7b6
tests: port test-minirst.py to Python 3
Augie Fackler <augie@google.com>
parents:
37881
diff
changeset
|
129 |
debugformats('lists', lists) |
9156
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
130 |
|
36706
87b8fc4533ca
py3: add b'' prefixes in tests/test-minirst.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31130
diff
changeset
|
131 |
options = b""" |
9156
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
132 |
There is support for simple option lists, |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
133 |
but only with long options: |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
134 |
|
13011
4936a04b6792
minirst: improved support for option lists.
Erik Zielke <ez@aragost.com>
parents:
13009
diff
changeset
|
135 |
-X, --exclude filter an option with a short and long option with an argument |
4936a04b6792
minirst: improved support for option lists.
Erik Zielke <ez@aragost.com>
parents:
13009
diff
changeset
|
136 |
-I, --include an option with both a short option and a long option |
4936a04b6792
minirst: improved support for option lists.
Erik Zielke <ez@aragost.com>
parents:
13009
diff
changeset
|
137 |
--all Output all. |
4936a04b6792
minirst: improved support for option lists.
Erik Zielke <ez@aragost.com>
parents:
13009
diff
changeset
|
138 |
--both Output both (this description is |
4936a04b6792
minirst: improved support for option lists.
Erik Zielke <ez@aragost.com>
parents:
13009
diff
changeset
|
139 |
quite long). |
4936a04b6792
minirst: improved support for option lists.
Erik Zielke <ez@aragost.com>
parents:
13009
diff
changeset
|
140 |
--long Output all day long. |
9156
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
141 |
|
13011
4936a04b6792
minirst: improved support for option lists.
Erik Zielke <ez@aragost.com>
parents:
13009
diff
changeset
|
142 |
--par This option has two paragraphs in its description. |
4936a04b6792
minirst: improved support for option lists.
Erik Zielke <ez@aragost.com>
parents:
13009
diff
changeset
|
143 |
This is the first. |
9156
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
144 |
|
13011
4936a04b6792
minirst: improved support for option lists.
Erik Zielke <ez@aragost.com>
parents:
13009
diff
changeset
|
145 |
This is the second. Blank lines may be omitted between |
4936a04b6792
minirst: improved support for option lists.
Erik Zielke <ez@aragost.com>
parents:
13009
diff
changeset
|
146 |
options (as above) or left in (as here). |
4936a04b6792
minirst: improved support for option lists.
Erik Zielke <ez@aragost.com>
parents:
13009
diff
changeset
|
147 |
|
9156
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
148 |
|
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
149 |
The next paragraph looks like an option list, but lacks the two-space |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
150 |
marker after the option. It is treated as a normal paragraph: |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
151 |
|
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
152 |
--foo bar baz |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
153 |
""" |
c9c7e8cdac9c
minimal reStructuredText parser
Martin Geisler <mg@lazybytes.net>
parents:
diff
changeset
|
154 |
|
37882
3d24f708f7b6
tests: port test-minirst.py to Python 3
Augie Fackler <augie@google.com>
parents:
37881
diff
changeset
|
155 |
debugformats('options', options) |
9293
e48a48b754d3
minirst: parse field lists
Martin Geisler <mg@lazybytes.net>
parents:
9291
diff
changeset
|
156 |
|
36706
87b8fc4533ca
py3: add b'' prefixes in tests/test-minirst.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31130
diff
changeset
|
157 |
fields = b""" |
10065
a1ae0ed78d1a
minirst: improve layout of field lists
Martin Geisler <mg@lazybytes.net>
parents:
9739
diff
changeset
|
158 |
:a: First item. |
a1ae0ed78d1a
minirst: improve layout of field lists
Martin Geisler <mg@lazybytes.net>
parents:
9739
diff
changeset
|
159 |
:ab: Second item. Indentation and wrapping |
a1ae0ed78d1a
minirst: improve layout of field lists
Martin Geisler <mg@lazybytes.net>
parents:
9739
diff
changeset
|
160 |
is handled automatically. |
46385
aaff3bc75306
minirst: respect escaping in definition list key
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43076
diff
changeset
|
161 |
:c\:d: a key with colon |
aaff3bc75306
minirst: respect escaping in definition list key
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43076
diff
changeset
|
162 |
:efg\:\:hh: a key with many colon |
9293
e48a48b754d3
minirst: parse field lists
Martin Geisler <mg@lazybytes.net>
parents:
9291
diff
changeset
|
163 |
|
10065
a1ae0ed78d1a
minirst: improve layout of field lists
Martin Geisler <mg@lazybytes.net>
parents:
9739
diff
changeset
|
164 |
Next list: |
a1ae0ed78d1a
minirst: improve layout of field lists
Martin Geisler <mg@lazybytes.net>
parents:
9739
diff
changeset
|
165 |
|
a1ae0ed78d1a
minirst: improve layout of field lists
Martin Geisler <mg@lazybytes.net>
parents:
9739
diff
changeset
|
166 |
:small: The larger key below triggers full indentation here. |
a1ae0ed78d1a
minirst: improve layout of field lists
Martin Geisler <mg@lazybytes.net>
parents:
9739
diff
changeset
|
167 |
:much too large: This key is big enough to get its own line. |
9293
e48a48b754d3
minirst: parse field lists
Martin Geisler <mg@lazybytes.net>
parents:
9291
diff
changeset
|
168 |
""" |
e48a48b754d3
minirst: parse field lists
Martin Geisler <mg@lazybytes.net>
parents:
9291
diff
changeset
|
169 |
|
37882
3d24f708f7b6
tests: port test-minirst.py to Python 3
Augie Fackler <augie@google.com>
parents:
37881
diff
changeset
|
170 |
debugformats('fields', fields) |
10443
62d484a81dfe
minirst: support containers
Martin Geisler <mg@lazybytes.net>
parents:
10289
diff
changeset
|
171 |
|
36706
87b8fc4533ca
py3: add b'' prefixes in tests/test-minirst.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31130
diff
changeset
|
172 |
containers = b""" |
10443
62d484a81dfe
minirst: support containers
Martin Geisler <mg@lazybytes.net>
parents:
10289
diff
changeset
|
173 |
Normal output. |
62d484a81dfe
minirst: support containers
Martin Geisler <mg@lazybytes.net>
parents:
10289
diff
changeset
|
174 |
|
62d484a81dfe
minirst: support containers
Martin Geisler <mg@lazybytes.net>
parents:
10289
diff
changeset
|
175 |
.. container:: debug |
62d484a81dfe
minirst: support containers
Martin Geisler <mg@lazybytes.net>
parents:
10289
diff
changeset
|
176 |
|
62d484a81dfe
minirst: support containers
Martin Geisler <mg@lazybytes.net>
parents:
10289
diff
changeset
|
177 |
Initial debug output. |
62d484a81dfe
minirst: support containers
Martin Geisler <mg@lazybytes.net>
parents:
10289
diff
changeset
|
178 |
|
62d484a81dfe
minirst: support containers
Martin Geisler <mg@lazybytes.net>
parents:
10289
diff
changeset
|
179 |
.. container:: verbose |
62d484a81dfe
minirst: support containers
Martin Geisler <mg@lazybytes.net>
parents:
10289
diff
changeset
|
180 |
|
62d484a81dfe
minirst: support containers
Martin Geisler <mg@lazybytes.net>
parents:
10289
diff
changeset
|
181 |
Verbose output. |
62d484a81dfe
minirst: support containers
Martin Geisler <mg@lazybytes.net>
parents:
10289
diff
changeset
|
182 |
|
62d484a81dfe
minirst: support containers
Martin Geisler <mg@lazybytes.net>
parents:
10289
diff
changeset
|
183 |
.. container:: debug |
62d484a81dfe
minirst: support containers
Martin Geisler <mg@lazybytes.net>
parents:
10289
diff
changeset
|
184 |
|
62d484a81dfe
minirst: support containers
Martin Geisler <mg@lazybytes.net>
parents:
10289
diff
changeset
|
185 |
Debug output. |
62d484a81dfe
minirst: support containers
Martin Geisler <mg@lazybytes.net>
parents:
10289
diff
changeset
|
186 |
""" |
62d484a81dfe
minirst: support containers
Martin Geisler <mg@lazybytes.net>
parents:
10289
diff
changeset
|
187 |
|
37882
3d24f708f7b6
tests: port test-minirst.py to Python 3
Augie Fackler <augie@google.com>
parents:
37881
diff
changeset
|
188 |
debugformats('containers (normal)', containers) |
3d24f708f7b6
tests: port test-minirst.py to Python 3
Augie Fackler <augie@google.com>
parents:
37881
diff
changeset
|
189 |
debugformats('containers (verbose)', containers, keep=[b'verbose']) |
3d24f708f7b6
tests: port test-minirst.py to Python 3
Augie Fackler <augie@google.com>
parents:
37881
diff
changeset
|
190 |
debugformats('containers (debug)', containers, keep=[b'debug']) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39310
diff
changeset
|
191 |
debugformats( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39310
diff
changeset
|
192 |
'containers (verbose debug)', containers, keep=[b'verbose', b'debug'] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39310
diff
changeset
|
193 |
) |
10972
0a2c6948f5f4
doc, minirst: support hg interpreted text role
Martin Geisler <mg@aragost.com>
parents:
10447
diff
changeset
|
194 |
|
36706
87b8fc4533ca
py3: add b'' prefixes in tests/test-minirst.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31130
diff
changeset
|
195 |
roles = b"""Please see :hg:`add`.""" |
37882
3d24f708f7b6
tests: port test-minirst.py to Python 3
Augie Fackler <augie@google.com>
parents:
37881
diff
changeset
|
196 |
debugformats('roles', roles) |
10977
f4778f942a4e
minirst: add test for sections
Martin Geisler <mg@lazybytes.net>
parents:
10972
diff
changeset
|
197 |
|
f4778f942a4e
minirst: add test for sections
Martin Geisler <mg@lazybytes.net>
parents:
10972
diff
changeset
|
198 |
|
36706
87b8fc4533ca
py3: add b'' prefixes in tests/test-minirst.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31130
diff
changeset
|
199 |
sections = b""" |
10984
68b7d2d668ce
minirst: support all recommended title adornments
Martin Geisler <mg@lazybytes.net>
parents:
10983
diff
changeset
|
200 |
Title |
68b7d2d668ce
minirst: support all recommended title adornments
Martin Geisler <mg@lazybytes.net>
parents:
10983
diff
changeset
|
201 |
===== |
68b7d2d668ce
minirst: support all recommended title adornments
Martin Geisler <mg@lazybytes.net>
parents:
10983
diff
changeset
|
202 |
|
68b7d2d668ce
minirst: support all recommended title adornments
Martin Geisler <mg@lazybytes.net>
parents:
10983
diff
changeset
|
203 |
Section |
68b7d2d668ce
minirst: support all recommended title adornments
Martin Geisler <mg@lazybytes.net>
parents:
10983
diff
changeset
|
204 |
------- |
68b7d2d668ce
minirst: support all recommended title adornments
Martin Geisler <mg@lazybytes.net>
parents:
10983
diff
changeset
|
205 |
|
68b7d2d668ce
minirst: support all recommended title adornments
Martin Geisler <mg@lazybytes.net>
parents:
10983
diff
changeset
|
206 |
Subsection |
68b7d2d668ce
minirst: support all recommended title adornments
Martin Geisler <mg@lazybytes.net>
parents:
10983
diff
changeset
|
207 |
'''''''''' |
10983
287a5cdf7743
minirst: correctly format sections containing inline markup
Martin Geisler <mg@lazybytes.net>
parents:
10977
diff
changeset
|
208 |
|
287a5cdf7743
minirst: correctly format sections containing inline markup
Martin Geisler <mg@lazybytes.net>
parents:
10977
diff
changeset
|
209 |
Markup: ``foo`` and :hg:`help` |
287a5cdf7743
minirst: correctly format sections containing inline markup
Martin Geisler <mg@lazybytes.net>
parents:
10977
diff
changeset
|
210 |
------------------------------ |
10977
f4778f942a4e
minirst: add test for sections
Martin Geisler <mg@lazybytes.net>
parents:
10972
diff
changeset
|
211 |
""" |
37882
3d24f708f7b6
tests: port test-minirst.py to Python 3
Augie Fackler <augie@google.com>
parents:
37881
diff
changeset
|
212 |
debugformats('sections', sections) |
12388
75f044d4dbf5
minirst: Support for admonitions
Erik Zielke <ez@aragost.com>
parents:
10984
diff
changeset
|
213 |
|
75f044d4dbf5
minirst: Support for admonitions
Erik Zielke <ez@aragost.com>
parents:
10984
diff
changeset
|
214 |
|
36706
87b8fc4533ca
py3: add b'' prefixes in tests/test-minirst.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31130
diff
changeset
|
215 |
admonitions = b""" |
12388
75f044d4dbf5
minirst: Support for admonitions
Erik Zielke <ez@aragost.com>
parents:
10984
diff
changeset
|
216 |
.. note:: |
19996
52b437586435
tests: modify minirst test input to new format
Simon Heimberg <simohe@besonet.ch>
parents:
16815
diff
changeset
|
217 |
|
12388
75f044d4dbf5
minirst: Support for admonitions
Erik Zielke <ez@aragost.com>
parents:
10984
diff
changeset
|
218 |
This is a note |
75f044d4dbf5
minirst: Support for admonitions
Erik Zielke <ez@aragost.com>
parents:
10984
diff
changeset
|
219 |
|
75f044d4dbf5
minirst: Support for admonitions
Erik Zielke <ez@aragost.com>
parents:
10984
diff
changeset
|
220 |
- Bullet 1 |
75f044d4dbf5
minirst: Support for admonitions
Erik Zielke <ez@aragost.com>
parents:
10984
diff
changeset
|
221 |
- Bullet 2 |
75f044d4dbf5
minirst: Support for admonitions
Erik Zielke <ez@aragost.com>
parents:
10984
diff
changeset
|
222 |
|
75f044d4dbf5
minirst: Support for admonitions
Erik Zielke <ez@aragost.com>
parents:
10984
diff
changeset
|
223 |
.. warning:: This is a warning Second |
75f044d4dbf5
minirst: Support for admonitions
Erik Zielke <ez@aragost.com>
parents:
10984
diff
changeset
|
224 |
input line of warning |
75f044d4dbf5
minirst: Support for admonitions
Erik Zielke <ez@aragost.com>
parents:
10984
diff
changeset
|
225 |
|
75f044d4dbf5
minirst: Support for admonitions
Erik Zielke <ez@aragost.com>
parents:
10984
diff
changeset
|
226 |
.. danger:: |
75f044d4dbf5
minirst: Support for admonitions
Erik Zielke <ez@aragost.com>
parents:
10984
diff
changeset
|
227 |
This is danger |
75f044d4dbf5
minirst: Support for admonitions
Erik Zielke <ez@aragost.com>
parents:
10984
diff
changeset
|
228 |
""" |
75f044d4dbf5
minirst: Support for admonitions
Erik Zielke <ez@aragost.com>
parents:
10984
diff
changeset
|
229 |
|
37882
3d24f708f7b6
tests: port test-minirst.py to Python 3
Augie Fackler <augie@google.com>
parents:
37881
diff
changeset
|
230 |
debugformats('admonitions', admonitions) |
12819
5082e2f3f8e0
minirst: ignore comments
Martin Geisler <mg@lazybytes.net>
parents:
12388
diff
changeset
|
231 |
|
36706
87b8fc4533ca
py3: add b'' prefixes in tests/test-minirst.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31130
diff
changeset
|
232 |
comments = b""" |
12819
5082e2f3f8e0
minirst: ignore comments
Martin Geisler <mg@lazybytes.net>
parents:
12388
diff
changeset
|
233 |
Some text. |
5082e2f3f8e0
minirst: ignore comments
Martin Geisler <mg@lazybytes.net>
parents:
12388
diff
changeset
|
234 |
|
5082e2f3f8e0
minirst: ignore comments
Martin Geisler <mg@lazybytes.net>
parents:
12388
diff
changeset
|
235 |
.. A comment |
5082e2f3f8e0
minirst: ignore comments
Martin Geisler <mg@lazybytes.net>
parents:
12388
diff
changeset
|
236 |
|
5082e2f3f8e0
minirst: ignore comments
Martin Geisler <mg@lazybytes.net>
parents:
12388
diff
changeset
|
237 |
.. An indented comment |
5082e2f3f8e0
minirst: ignore comments
Martin Geisler <mg@lazybytes.net>
parents:
12388
diff
changeset
|
238 |
|
5082e2f3f8e0
minirst: ignore comments
Martin Geisler <mg@lazybytes.net>
parents:
12388
diff
changeset
|
239 |
Some indented text. |
13009
54be08fa4d1d
minirst: modified minirst to also recognize empty comments.
Erik Zielke <ez@aragost.com>
parents:
12865
diff
changeset
|
240 |
|
54be08fa4d1d
minirst: modified minirst to also recognize empty comments.
Erik Zielke <ez@aragost.com>
parents:
12865
diff
changeset
|
241 |
.. |
54be08fa4d1d
minirst: modified minirst to also recognize empty comments.
Erik Zielke <ez@aragost.com>
parents:
12865
diff
changeset
|
242 |
|
54be08fa4d1d
minirst: modified minirst to also recognize empty comments.
Erik Zielke <ez@aragost.com>
parents:
12865
diff
changeset
|
243 |
Empty comment above |
12819
5082e2f3f8e0
minirst: ignore comments
Martin Geisler <mg@lazybytes.net>
parents:
12388
diff
changeset
|
244 |
""" |
5082e2f3f8e0
minirst: ignore comments
Martin Geisler <mg@lazybytes.net>
parents:
12388
diff
changeset
|
245 |
|
37882
3d24f708f7b6
tests: port test-minirst.py to Python 3
Augie Fackler <augie@google.com>
parents:
37881
diff
changeset
|
246 |
debugformats('comments', comments) |
15037
df47381b41d6
minirst: add simple table support
Matt Mackall <mpm@selenic.com>
parents:
13011
diff
changeset
|
247 |
|
15039
c981f4a9ea74
minirst: add a helper function to build an RST table from an array
Matt Mackall <mpm@selenic.com>
parents:
15037
diff
changeset
|
248 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39310
diff
changeset
|
249 |
data = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39310
diff
changeset
|
250 |
[b'a', b'b', b'c'], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39310
diff
changeset
|
251 |
[b'1', b'2', b'3'], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39310
diff
changeset
|
252 |
[b'foo', b'bar', b'baz this list is very very very long man'], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39310
diff
changeset
|
253 |
] |
15039
c981f4a9ea74
minirst: add a helper function to build an RST table from an array
Matt Mackall <mpm@selenic.com>
parents:
15037
diff
changeset
|
254 |
|
16815
e740746ea557
minirst: generate tables as a list of joined lines
Olav Reinert <seroton10@gmail.com>
parents:
15263
diff
changeset
|
255 |
rst = minirst.maketable(data, 2, True) |
36706
87b8fc4533ca
py3: add b'' prefixes in tests/test-minirst.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31130
diff
changeset
|
256 |
table = b''.join(rst) |
15039
c981f4a9ea74
minirst: add a helper function to build an RST table from an array
Matt Mackall <mpm@selenic.com>
parents:
15037
diff
changeset
|
257 |
|
37882
3d24f708f7b6
tests: port test-minirst.py to Python 3
Augie Fackler <augie@google.com>
parents:
37881
diff
changeset
|
258 |
print(table.decode('utf8')) |
15037
df47381b41d6
minirst: add simple table support
Matt Mackall <mpm@selenic.com>
parents:
13011
diff
changeset
|
259 |
|
37882
3d24f708f7b6
tests: port test-minirst.py to Python 3
Augie Fackler <augie@google.com>
parents:
37881
diff
changeset
|
260 |
debugformats('table', table) |
20654
af9d9b778550
minirst: create valid output when table data contains a newline
Simon Heimberg <simohe@besonet.ch>
parents:
19996
diff
changeset
|
261 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39310
diff
changeset
|
262 |
data = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39310
diff
changeset
|
263 |
[b's', b'long', b'line\ngoes on here'], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39310
diff
changeset
|
264 |
[b'', b'xy', b'tried to fix here\n by indenting'], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39310
diff
changeset
|
265 |
] |
20654
af9d9b778550
minirst: create valid output when table data contains a newline
Simon Heimberg <simohe@besonet.ch>
parents:
19996
diff
changeset
|
266 |
|
af9d9b778550
minirst: create valid output when table data contains a newline
Simon Heimberg <simohe@besonet.ch>
parents:
19996
diff
changeset
|
267 |
rst = minirst.maketable(data, 1, False) |
36706
87b8fc4533ca
py3: add b'' prefixes in tests/test-minirst.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31130
diff
changeset
|
268 |
table = b''.join(rst) |
20654
af9d9b778550
minirst: create valid output when table data contains a newline
Simon Heimberg <simohe@besonet.ch>
parents:
19996
diff
changeset
|
269 |
|
37882
3d24f708f7b6
tests: port test-minirst.py to Python 3
Augie Fackler <augie@google.com>
parents:
37881
diff
changeset
|
270 |
print(table.decode('utf8')) |
20654
af9d9b778550
minirst: create valid output when table data contains a newline
Simon Heimberg <simohe@besonet.ch>
parents:
19996
diff
changeset
|
271 |
|
37882
3d24f708f7b6
tests: port test-minirst.py to Python 3
Augie Fackler <augie@google.com>
parents:
37881
diff
changeset
|
272 |
debugformats('table+nl', table) |