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