1 from pprint import pprint |
1 from pprint import pprint |
2 from mercurial import minirst |
2 from mercurial import minirst |
3 |
3 |
4 def debugformat(title, text, width, **kwargs): |
4 def debugformat(text, form, **kwargs): |
5 print "%s formatted to fit within %d characters:" % (title, width) |
5 if form == 'html': |
6 formatted = minirst.format(text, width, **kwargs) |
6 print "html format:" |
7 html = minirst.format(text, width, style='html', **kwargs) |
7 out = minirst.format(text, style=form, **kwargs) |
|
8 else: |
|
9 print "%d column format:" % form |
|
10 out = minirst.format(text, width=form, **kwargs) |
|
11 |
8 print "-" * 70 |
12 print "-" * 70 |
9 if type(formatted) == tuple: |
13 if type(out) == tuple: |
10 print formatted[0] |
14 print out[0][:-1] |
11 print "-" * 70 |
15 print "-" * 70 |
12 print html |
16 pprint(out[1]) |
13 print "-" * 70 |
|
14 pprint(formatted[1]) |
|
15 else: |
17 else: |
16 print formatted |
18 print out[:-1] |
17 print "-" * 70 |
|
18 print html |
|
19 print "-" * 70 |
19 print "-" * 70 |
20 print |
20 print |
|
21 |
|
22 def debugformats(title, text, **kwargs): |
|
23 print "== %s ==" % title |
|
24 debugformat(text, 60, **kwargs) |
|
25 debugformat(text, 30, **kwargs) |
|
26 debugformat(text, 'html', **kwargs) |
21 |
27 |
22 paragraphs = """ |
28 paragraphs = """ |
23 This is some text in the first paragraph. |
29 This is some text in the first paragraph. |
24 |
30 |
25 A small indented paragraph. |
31 A small indented paragraph. |
26 It is followed by some lines |
32 It is followed by some lines |
27 containing random whitespace. |
33 containing random whitespace. |
28 \n \n \nThe third and final paragraph. |
34 \n \n \nThe third and final paragraph. |
29 """ |
35 """ |
30 |
36 |
31 debugformat('paragraphs', paragraphs, 60) |
37 debugformats('paragraphs', paragraphs) |
32 debugformat('paragraphs', paragraphs, 30) |
|
33 |
|
34 |
38 |
35 definitions = """ |
39 definitions = """ |
36 A Term |
40 A Term |
37 Definition. The indented |
41 Definition. The indented |
38 lines make up the definition. |
42 lines make up the definition. |
69 This literal block is started with '::', |
71 This literal block is started with '::', |
70 the so-called expanded form. The paragraph |
72 the so-called expanded form. The paragraph |
71 with '::' disappears in the final output. |
73 with '::' disappears in the final output. |
72 """ |
74 """ |
73 |
75 |
74 debugformat('literals', literals, 60) |
76 debugformats('literals', literals) |
75 debugformat('literals', literals, 30) |
|
76 |
|
77 |
77 |
78 lists = """ |
78 lists = """ |
79 - This is the first list item. |
79 - This is the first list item. |
80 |
80 |
81 Second paragraph in the first list item. |
81 Second paragraph in the first list item. |
115 | This is the first line. |
115 | This is the first line. |
116 The line continues here. |
116 The line continues here. |
117 | This is the second line. |
117 | This is the second line. |
118 """ |
118 """ |
119 |
119 |
120 debugformat('lists', lists, 60) |
120 debugformats('lists', lists) |
121 debugformat('lists', lists, 30) |
|
122 |
|
123 |
121 |
124 options = """ |
122 options = """ |
125 There is support for simple option lists, |
123 There is support for simple option lists, |
126 but only with long options: |
124 but only with long options: |
127 |
125 |
143 marker after the option. It is treated as a normal paragraph: |
141 marker after the option. It is treated as a normal paragraph: |
144 |
142 |
145 --foo bar baz |
143 --foo bar baz |
146 """ |
144 """ |
147 |
145 |
148 debugformat('options', options, 60) |
146 debugformats('options', options) |
149 debugformat('options', options, 30) |
|
150 |
|
151 |
147 |
152 fields = """ |
148 fields = """ |
153 :a: First item. |
149 :a: First item. |
154 :ab: Second item. Indentation and wrapping |
150 :ab: Second item. Indentation and wrapping |
155 is handled automatically. |
151 is handled automatically. |
177 .. container:: debug |
172 .. container:: debug |
178 |
173 |
179 Debug output. |
174 Debug output. |
180 """ |
175 """ |
181 |
176 |
182 debugformat('containers (normal)', containers, 60) |
177 debugformats('containers (normal)', containers) |
183 debugformat('containers (verbose)', containers, 60, keep=['verbose']) |
178 debugformats('containers (verbose)', containers, keep=['verbose']) |
184 debugformat('containers (debug)', containers, 60, keep=['debug']) |
179 debugformats('containers (debug)', containers, keep=['debug']) |
185 debugformat('containers (verbose debug)', containers, 60, |
180 debugformats('containers (verbose debug)', containers, |
186 keep=['verbose', 'debug']) |
181 keep=['verbose', 'debug']) |
187 |
182 |
188 roles = """Please see :hg:`add`.""" |
183 roles = """Please see :hg:`add`.""" |
189 debugformat('roles', roles, 60) |
184 debugformats('roles', roles) |
190 |
185 |
191 |
186 |
192 sections = """ |
187 sections = """ |
193 Title |
188 Title |
194 ===== |
189 ===== |
233 .. |
228 .. |
234 |
229 |
235 Empty comment above |
230 Empty comment above |
236 """ |
231 """ |
237 |
232 |
238 debugformat('comments', comments, 30) |
233 debugformats('comments', comments) |
239 |
234 |
240 |
235 |
241 data = [['a', 'b', 'c'], |
236 data = [['a', 'b', 'c'], |
242 ['1', '2', '3'], |
237 ['1', '2', '3'], |
243 ['foo', 'bar', 'baz this list is very very very long man']] |
238 ['foo', 'bar', 'baz this list is very very very long man']] |
244 |
239 |
245 table = minirst.maketable(data, 2, True) |
240 table = minirst.maketable(data, 2, True) |
246 |
241 |
247 print table |
242 print table |
248 |
243 |
249 debugformat('table', table, 30) |
244 debugformats('table', table) |