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