##// END OF EJS Templates
minirst: improved support for option lists....
Erik Zielke -
r13011:4936a04b default
parent child Browse files
Show More
@@ -99,7 +99,8 b' def findliteralblocks(blocks):'
99 99 return blocks
100 100
101 101 _bulletre = re.compile(r'(-|[0-9A-Za-z]+\.|\(?[0-9A-Za-z]+\)|\|) ')
102 _optionre = re.compile(r'^(--[a-z-]+)((?:[ =][a-zA-Z][\w-]*)? +)(.*)$')
102 _optionre = re.compile(r'^(-([a-zA-Z0-9]), )?(--[a-z0-9-]+)'
103 r'((.*) +)(.*)$')
103 104 _fieldre = re.compile(r':(?![: ])([^:]*)(?<! ):[ ]+(.*)')
104 105 _definitionre = re.compile(r'[^ ]')
105 106
@@ -173,6 +174,42 b' def updatefieldlists(blocks):'
173 174 return blocks
174 175
175 176
177 def updateoptionlists(blocks):
178 i = 0
179 while i < len(blocks):
180 if blocks[i]['type'] != 'option':
181 i += 1
182 continue
183
184 optstrwidth = 0
185 j = i
186 while j < len(blocks) and blocks[j]['type'] == 'option':
187 m = _optionre.match(blocks[j]['lines'][0])
188
189 shortoption = m.group(2)
190 group3 = m.group(3)
191 longoption = group3[2:].strip()
192 desc = m.group(6).strip()
193 longoptionarg = m.group(5).strip()
194 blocks[j]['lines'][0] = desc
195
196 noshortop = ''
197 if not shortoption:
198 noshortop = ' '
199
200 opt = "%s%s" % (shortoption and "-%s " % shortoption or '',
201 ("%s--%s %s") % (noshortop, longoption,
202 longoptionarg))
203 opt = opt.rstrip()
204 blocks[j]['optstr'] = opt
205 optstrwidth = max(optstrwidth, encoding.colwidth(opt))
206 j += 1
207
208 for block in blocks[i:j]:
209 block['optstrwidth'] = optstrwidth
210 i = j + 1
211 return blocks
212
176 213 def prunecontainers(blocks, keep):
177 214 """Prune unwanted containers.
178 215
@@ -322,6 +359,17 b' def findadmonitions(blocks):'
322 359 'tip': _('Tip:'),
323 360 'warning': _('Warning!')}
324 361
362 def formatoption(block, width):
363 desc = ' '.join(map(str.strip, block['lines']))
364 colwidth = encoding.colwidth(block['optstr'])
365 usablewidth = width - 1
366 hanging = block['optstrwidth']
367 initindent = '%s%s ' % (block['optstr'], ' ' * ((hanging - colwidth)))
368 hangindent = ' ' * (encoding.colwidth(initindent) + 1)
369 return ' %s' % (util.wrap(desc, usablewidth,
370 initindent=initindent,
371 hangindent=hangindent))
372
325 373 def formatblock(block, width):
326 374 """Format a block according to width."""
327 375 if width <= 0:
@@ -378,9 +426,7 b' def formatblock(block, width):'
378 426 key = key.ljust(_fieldwidth)
379 427 block['lines'][0] = key + block['lines'][0]
380 428 elif block['type'] == 'option':
381 m = _optionre.match(block['lines'][0])
382 option, arg, rest = m.groups()
383 subindent = indent + (len(option) + len(arg)) * ' '
429 return formatoption(block, width)
384 430
385 431 text = ' '.join(map(str.strip, block['lines']))
386 432 return util.wrap(text, width=width,
@@ -400,6 +446,7 b' def format(text, width, indent=0, keep=N'
400 446 blocks = hgrole(blocks)
401 447 blocks = splitparagraphs(blocks)
402 448 blocks = updatefieldlists(blocks)
449 blocks = updateoptionlists(blocks)
403 450 blocks = addmargins(blocks)
404 451 blocks = prunecomments(blocks)
405 452 blocks = findadmonitions(blocks)
@@ -427,6 +474,7 b' if __name__ == "__main__":'
427 474 blocks = debug(inlineliterals, blocks)
428 475 blocks = debug(splitparagraphs, blocks)
429 476 blocks = debug(updatefieldlists, blocks)
477 blocks = debug(updateoptionlists, blocks)
430 478 blocks = debug(findsections, blocks)
431 479 blocks = debug(addmargins, blocks)
432 480 blocks = debug(prunecomments, blocks)
@@ -40,8 +40,8 b''
40 40 have the following effects:
41 41
42 42 --branchsort convert from parent to child revision when possible, which
43 means branches are usually converted one after the other. It
44 generates more compact repositories.
43 means branches are usually converted one after the other.
44 It generates more compact repositories.
45 45 --datesort sort revisions by date. Converted repositories have good-
46 46 looking changelogs but are often an order of magnitude
47 47 larger than the same ones generated by --branchsort.
@@ -120,16 +120,19 b' options = """'
120 120 There is support for simple option lists,
121 121 but only with long options:
122 122
123 --all Output all.
124 --both Output both (this description is
125 quite long).
126 --long Output all day long.
123 -X, --exclude filter an option with a short and long option with an argument
124 -I, --include an option with both a short option and a long option
125 --all Output all.
126 --both Output both (this description is
127 quite long).
128 --long Output all day long.
127 129
128 --par This option has two paragraphs in its description.
129 This is the first.
130 --par This option has two paragraphs in its description.
131 This is the first.
130 132
131 This is the second. Blank lines may be omitted between
132 options (as above) or left in (as here).
133 This is the second. Blank lines may be omitted between
134 options (as above) or left in (as here).
135
133 136
134 137 The next paragraph looks like an option list, but lacks the two-space
135 138 marker after the option. It is treated as a normal paragraph:
@@ -180,14 +180,20 b' options formatted to fit within 60 chara'
180 180 There is support for simple option lists, but only with long
181 181 options:
182 182
183 --all Output all.
184 --both Output both (this description is quite long).
185 --long Output all day long.
186 --par This option has two paragraphs in its
187 description. This is the first.
183 -X --exclude filter an option with a short and long option
184 with an argument
185 -I --include an option with both a short option and
186 a long option
187 --all Output all.
188 --both Output both (this description is quite
189 long).
190 --long Output all day long.
191 --par This option has two paragraphs in its
192 description. This is the first.
188 193
189 This is the second. Blank lines may be omitted
190 between options (as above) or left in (as here).
194 This is the second. Blank lines may
195 be omitted between options (as above)
196 or left in (as here).
191 197
192 198 The next paragraph looks like an option list, but lacks the
193 199 two-space marker after the option. It is treated as a normal
@@ -202,23 +208,62 b' There is support for simple'
202 208 option lists, but only with
203 209 long options:
204 210
205 --all Output all.
206 --both Output both (this
207 description is
208 quite long).
209 --long Output all day
210 long.
211 --par This option has two
212 paragraphs in its
213 description. This
214 is the first.
211 -X --exclude filter an
212 option
213 with a
214 short
215 and
216 long
217 option
218 with an
219 argumen
220 t
221 -I --include an
222 option
223 with
224 both a
225 short
226 option
227 and a
228 long
229 option
230 --all Output
231 all.
232 --both Output
233 both
234 (this d
235 escript
236 ion is
237 quite
238 long).
239 --long Output
240 all day
241 long.
242 --par This
243 option
244 has two
245 paragra
246 phs in
247 its des
248 criptio
249 n. This
250 is the
251 first.
215 252
216 This is the second.
217 Blank lines may be
218 omitted between
219 options (as above)
220 or left in (as
221 here).
253 This is
254 the
255 second.
256 Blank
257 lines
258 may be
259 omitted
260 between
261 options
262 (as
263 above)
264 or left
265 in (as
266 here).
222 267
223 268 The next paragraph looks like
224 269 an option list, but lacks the
General Comments 0
You need to be logged in to leave comments. Login now