Show More
@@ -1,268 +1,268 b'' | |||
|
1 | 1 | from __future__ import absolute_import, print_function |
|
2 | 2 | from mercurial import ( |
|
3 | 3 | minirst, |
|
4 | 4 | ) |
|
5 | 5 | from mercurial.utils import ( |
|
6 | 6 | stringutil, |
|
7 | 7 | ) |
|
8 | 8 | |
|
9 | 9 | def debugformat(text, form, **kwargs): |
|
10 | if form == 'html': | |
|
10 | if form == b'html': | |
|
11 | 11 | print("html format:") |
|
12 | 12 | out = minirst.format(text, style=form, **kwargs) |
|
13 | 13 | else: |
|
14 | 14 | print("%d column format:" % form) |
|
15 | 15 | out = minirst.format(text, width=form, **kwargs) |
|
16 | 16 | |
|
17 | 17 | print("-" * 70) |
|
18 | 18 | if type(out) == tuple: |
|
19 | print(out[0][:-1]) | |
|
19 | print(out[0][:-1].decode('utf8')) | |
|
20 | 20 | print("-" * 70) |
|
21 | print(stringutil.pprint(out[1], bprefix=False)) | |
|
21 | print(stringutil.pprint(out[1], bprefix=False).decode('utf8')) | |
|
22 | 22 | else: |
|
23 | print(out[:-1]) | |
|
23 | print(out[:-1].decode('utf8')) | |
|
24 | 24 | print("-" * 70) |
|
25 | 25 | print() |
|
26 | 26 | |
|
27 | 27 | def debugformats(title, text, **kwargs): |
|
28 | 28 | print("== %s ==" % title) |
|
29 | 29 | debugformat(text, 60, **kwargs) |
|
30 | 30 | debugformat(text, 30, **kwargs) |
|
31 | debugformat(text, 'html', **kwargs) | |
|
31 | debugformat(text, b'html', **kwargs) | |
|
32 | 32 | |
|
33 | 33 | paragraphs = b""" |
|
34 | 34 | This is some text in the first paragraph. |
|
35 | 35 | |
|
36 | 36 | A small indented paragraph. |
|
37 | 37 | It is followed by some lines |
|
38 | 38 | containing random whitespace. |
|
39 | 39 | \n \n \nThe third and final paragraph. |
|
40 | 40 | """ |
|
41 | 41 | |
|
42 |
debugformats( |
|
|
42 | debugformats('paragraphs', paragraphs) | |
|
43 | 43 | |
|
44 | 44 | definitions = b""" |
|
45 | 45 | A Term |
|
46 | 46 | Definition. The indented |
|
47 | 47 | lines make up the definition. |
|
48 | 48 | Another Term |
|
49 | 49 | Another definition. The final line in the |
|
50 | 50 | definition determines the indentation, so |
|
51 | 51 | this will be indented with four spaces. |
|
52 | 52 | |
|
53 | 53 | A Nested/Indented Term |
|
54 | 54 | Definition. |
|
55 | 55 | """ |
|
56 | 56 | |
|
57 |
debugformats( |
|
|
57 | debugformats('definitions', definitions) | |
|
58 | 58 | |
|
59 | 59 | literals = br""" |
|
60 | 60 | The fully minimized form is the most |
|
61 | 61 | convenient form:: |
|
62 | 62 | |
|
63 | 63 | Hello |
|
64 | 64 | literal |
|
65 | 65 | world |
|
66 | 66 | |
|
67 | 67 | In the partially minimized form a paragraph |
|
68 | 68 | simply ends with space-double-colon. :: |
|
69 | 69 | |
|
70 | 70 | //////////////////////////////////////// |
|
71 | 71 | long un-wrapped line in a literal block |
|
72 | 72 | \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ |
|
73 | 73 | |
|
74 | 74 | :: |
|
75 | 75 | |
|
76 | 76 | This literal block is started with '::', |
|
77 | 77 | the so-called expanded form. The paragraph |
|
78 | 78 | with '::' disappears in the final output. |
|
79 | 79 | """ |
|
80 | 80 | |
|
81 |
debugformats( |
|
|
81 | debugformats('literals', literals) | |
|
82 | 82 | |
|
83 | 83 | lists = b""" |
|
84 | 84 | - This is the first list item. |
|
85 | 85 | |
|
86 | 86 | Second paragraph in the first list item. |
|
87 | 87 | |
|
88 | 88 | - List items need not be separated |
|
89 | 89 | by a blank line. |
|
90 | 90 | - And will be rendered without |
|
91 | 91 | one in any case. |
|
92 | 92 | |
|
93 | 93 | We can have indented lists: |
|
94 | 94 | |
|
95 | 95 | - This is an indented list item |
|
96 | 96 | |
|
97 | 97 | - Another indented list item:: |
|
98 | 98 | |
|
99 | 99 | - A literal block in the middle |
|
100 | 100 | of an indented list. |
|
101 | 101 | |
|
102 | 102 | (The above is not a list item since we are in the literal block.) |
|
103 | 103 | |
|
104 | 104 | :: |
|
105 | 105 | |
|
106 | 106 | Literal block with no indentation (apart from |
|
107 | 107 | the two spaces added to all literal blocks). |
|
108 | 108 | |
|
109 | 109 | 1. This is an enumerated list (first item). |
|
110 | 110 | 2. Continuing with the second item. |
|
111 | 111 | |
|
112 | 112 | (1) foo |
|
113 | 113 | (2) bar |
|
114 | 114 | |
|
115 | 115 | 1) Another |
|
116 | 116 | 2) List |
|
117 | 117 | |
|
118 | 118 | Line blocks are also a form of list: |
|
119 | 119 | |
|
120 | 120 | | This is the first line. |
|
121 | 121 | The line continues here. |
|
122 | 122 | | This is the second line. |
|
123 | 123 | |
|
124 | 124 | Bullet lists are also detected: |
|
125 | 125 | |
|
126 | 126 | * This is the first bullet |
|
127 | 127 | * This is the second bullet |
|
128 | 128 | It has 2 lines |
|
129 | 129 | * This is the third bullet |
|
130 | 130 | """ |
|
131 | 131 | |
|
132 |
debugformats( |
|
|
132 | debugformats('lists', lists) | |
|
133 | 133 | |
|
134 | 134 | options = b""" |
|
135 | 135 | There is support for simple option lists, |
|
136 | 136 | but only with long options: |
|
137 | 137 | |
|
138 | 138 | -X, --exclude filter an option with a short and long option with an argument |
|
139 | 139 | -I, --include an option with both a short option and a long option |
|
140 | 140 | --all Output all. |
|
141 | 141 | --both Output both (this description is |
|
142 | 142 | quite long). |
|
143 | 143 | --long Output all day long. |
|
144 | 144 | |
|
145 | 145 | --par This option has two paragraphs in its description. |
|
146 | 146 | This is the first. |
|
147 | 147 | |
|
148 | 148 | This is the second. Blank lines may be omitted between |
|
149 | 149 | options (as above) or left in (as here). |
|
150 | 150 | |
|
151 | 151 | |
|
152 | 152 | The next paragraph looks like an option list, but lacks the two-space |
|
153 | 153 | marker after the option. It is treated as a normal paragraph: |
|
154 | 154 | |
|
155 | 155 | --foo bar baz |
|
156 | 156 | """ |
|
157 | 157 | |
|
158 |
debugformats( |
|
|
158 | debugformats('options', options) | |
|
159 | 159 | |
|
160 | 160 | fields = b""" |
|
161 | 161 | :a: First item. |
|
162 | 162 | :ab: Second item. Indentation and wrapping |
|
163 | 163 | is handled automatically. |
|
164 | 164 | |
|
165 | 165 | Next list: |
|
166 | 166 | |
|
167 | 167 | :small: The larger key below triggers full indentation here. |
|
168 | 168 | :much too large: This key is big enough to get its own line. |
|
169 | 169 | """ |
|
170 | 170 | |
|
171 |
debugformats( |
|
|
171 | debugformats('fields', fields) | |
|
172 | 172 | |
|
173 | 173 | containers = b""" |
|
174 | 174 | Normal output. |
|
175 | 175 | |
|
176 | 176 | .. container:: debug |
|
177 | 177 | |
|
178 | 178 | Initial debug output. |
|
179 | 179 | |
|
180 | 180 | .. container:: verbose |
|
181 | 181 | |
|
182 | 182 | Verbose output. |
|
183 | 183 | |
|
184 | 184 | .. container:: debug |
|
185 | 185 | |
|
186 | 186 | Debug output. |
|
187 | 187 | """ |
|
188 | 188 | |
|
189 |
debugformats( |
|
|
190 |
debugformats( |
|
|
191 |
debugformats( |
|
|
192 |
debugformats( |
|
|
193 | keep=['verbose', 'debug']) | |
|
189 | debugformats('containers (normal)', containers) | |
|
190 | debugformats('containers (verbose)', containers, keep=[b'verbose']) | |
|
191 | debugformats('containers (debug)', containers, keep=[b'debug']) | |
|
192 | debugformats('containers (verbose debug)', containers, | |
|
193 | keep=[b'verbose', b'debug']) | |
|
194 | 194 | |
|
195 | 195 | roles = b"""Please see :hg:`add`.""" |
|
196 |
debugformats( |
|
|
196 | debugformats('roles', roles) | |
|
197 | 197 | |
|
198 | 198 | |
|
199 | 199 | sections = b""" |
|
200 | 200 | Title |
|
201 | 201 | ===== |
|
202 | 202 | |
|
203 | 203 | Section |
|
204 | 204 | ------- |
|
205 | 205 | |
|
206 | 206 | Subsection |
|
207 | 207 | '''''''''' |
|
208 | 208 | |
|
209 | 209 | Markup: ``foo`` and :hg:`help` |
|
210 | 210 | ------------------------------ |
|
211 | 211 | """ |
|
212 |
debugformats( |
|
|
212 | debugformats('sections', sections) | |
|
213 | 213 | |
|
214 | 214 | |
|
215 | 215 | admonitions = b""" |
|
216 | 216 | .. note:: |
|
217 | 217 | |
|
218 | 218 | This is a note |
|
219 | 219 | |
|
220 | 220 | - Bullet 1 |
|
221 | 221 | - Bullet 2 |
|
222 | 222 | |
|
223 | 223 | .. warning:: This is a warning Second |
|
224 | 224 | input line of warning |
|
225 | 225 | |
|
226 | 226 | .. danger:: |
|
227 | 227 | This is danger |
|
228 | 228 | """ |
|
229 | 229 | |
|
230 |
debugformats( |
|
|
230 | debugformats('admonitions', admonitions) | |
|
231 | 231 | |
|
232 | 232 | comments = b""" |
|
233 | 233 | Some text. |
|
234 | 234 | |
|
235 | 235 | .. A comment |
|
236 | 236 | |
|
237 | 237 | .. An indented comment |
|
238 | 238 | |
|
239 | 239 | Some indented text. |
|
240 | 240 | |
|
241 | 241 | .. |
|
242 | 242 | |
|
243 | 243 | Empty comment above |
|
244 | 244 | """ |
|
245 | 245 | |
|
246 |
debugformats( |
|
|
246 | debugformats('comments', comments) | |
|
247 | 247 | |
|
248 | 248 | |
|
249 | 249 | data = [[b'a', b'b', b'c'], |
|
250 | 250 | [b'1', b'2', b'3'], |
|
251 | 251 | [b'foo', b'bar', b'baz this list is very very very long man']] |
|
252 | 252 | |
|
253 | 253 | rst = minirst.maketable(data, 2, True) |
|
254 | 254 | table = b''.join(rst) |
|
255 | 255 | |
|
256 | print(table) | |
|
256 | print(table.decode('utf8')) | |
|
257 | 257 | |
|
258 |
debugformats( |
|
|
258 | debugformats('table', table) | |
|
259 | 259 | |
|
260 | 260 | data = [[b's', b'long', b'line\ngoes on here'], |
|
261 | 261 | [b'', b'xy', b'tried to fix here\n by indenting']] |
|
262 | 262 | |
|
263 | 263 | rst = minirst.maketable(data, 1, False) |
|
264 | 264 | table = b''.join(rst) |
|
265 | 265 | |
|
266 | print(table) | |
|
266 | print(table.decode('utf8')) | |
|
267 | 267 | |
|
268 |
debugformats( |
|
|
268 | debugformats('table+nl', table) |
General Comments 0
You need to be logged in to leave comments.
Login now