##// 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 return blocks
99 return blocks
100
100
101 _bulletre = re.compile(r'(-|[0-9A-Za-z]+\.|\(?[0-9A-Za-z]+\)|\|) ')
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 _fieldre = re.compile(r':(?![: ])([^:]*)(?<! ):[ ]+(.*)')
104 _fieldre = re.compile(r':(?![: ])([^:]*)(?<! ):[ ]+(.*)')
104 _definitionre = re.compile(r'[^ ]')
105 _definitionre = re.compile(r'[^ ]')
105
106
@@ -173,6 +174,42 b' def updatefieldlists(blocks):'
173 return blocks
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 def prunecontainers(blocks, keep):
213 def prunecontainers(blocks, keep):
177 """Prune unwanted containers.
214 """Prune unwanted containers.
178
215
@@ -322,6 +359,17 b' def findadmonitions(blocks):'
322 'tip': _('Tip:'),
359 'tip': _('Tip:'),
323 'warning': _('Warning!')}
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 def formatblock(block, width):
373 def formatblock(block, width):
326 """Format a block according to width."""
374 """Format a block according to width."""
327 if width <= 0:
375 if width <= 0:
@@ -378,9 +426,7 b' def formatblock(block, width):'
378 key = key.ljust(_fieldwidth)
426 key = key.ljust(_fieldwidth)
379 block['lines'][0] = key + block['lines'][0]
427 block['lines'][0] = key + block['lines'][0]
380 elif block['type'] == 'option':
428 elif block['type'] == 'option':
381 m = _optionre.match(block['lines'][0])
429 return formatoption(block, width)
382 option, arg, rest = m.groups()
383 subindent = indent + (len(option) + len(arg)) * ' '
384
430
385 text = ' '.join(map(str.strip, block['lines']))
431 text = ' '.join(map(str.strip, block['lines']))
386 return util.wrap(text, width=width,
432 return util.wrap(text, width=width,
@@ -400,6 +446,7 b' def format(text, width, indent=0, keep=N'
400 blocks = hgrole(blocks)
446 blocks = hgrole(blocks)
401 blocks = splitparagraphs(blocks)
447 blocks = splitparagraphs(blocks)
402 blocks = updatefieldlists(blocks)
448 blocks = updatefieldlists(blocks)
449 blocks = updateoptionlists(blocks)
403 blocks = addmargins(blocks)
450 blocks = addmargins(blocks)
404 blocks = prunecomments(blocks)
451 blocks = prunecomments(blocks)
405 blocks = findadmonitions(blocks)
452 blocks = findadmonitions(blocks)
@@ -427,6 +474,7 b' if __name__ == "__main__":'
427 blocks = debug(inlineliterals, blocks)
474 blocks = debug(inlineliterals, blocks)
428 blocks = debug(splitparagraphs, blocks)
475 blocks = debug(splitparagraphs, blocks)
429 blocks = debug(updatefieldlists, blocks)
476 blocks = debug(updatefieldlists, blocks)
477 blocks = debug(updateoptionlists, blocks)
430 blocks = debug(findsections, blocks)
478 blocks = debug(findsections, blocks)
431 blocks = debug(addmargins, blocks)
479 blocks = debug(addmargins, blocks)
432 blocks = debug(prunecomments, blocks)
480 blocks = debug(prunecomments, blocks)
@@ -40,8 +40,8 b''
40 have the following effects:
40 have the following effects:
41
41
42 --branchsort convert from parent to child revision when possible, which
42 --branchsort convert from parent to child revision when possible, which
43 means branches are usually converted one after the other. It
43 means branches are usually converted one after the other.
44 generates more compact repositories.
44 It generates more compact repositories.
45 --datesort sort revisions by date. Converted repositories have good-
45 --datesort sort revisions by date. Converted repositories have good-
46 looking changelogs but are often an order of magnitude
46 looking changelogs but are often an order of magnitude
47 larger than the same ones generated by --branchsort.
47 larger than the same ones generated by --branchsort.
@@ -120,16 +120,19 b' options = """'
120 There is support for simple option lists,
120 There is support for simple option lists,
121 but only with long options:
121 but only with long options:
122
122
123 --all Output all.
123 -X, --exclude filter an option with a short and long option with an argument
124 --both Output both (this description is
124 -I, --include an option with both a short option and a long option
125 quite long).
125 --all Output all.
126 --long Output all day long.
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.
130 --par This option has two paragraphs in its description.
129 This is the first.
131 This is the first.
130
132
131 This is the second. Blank lines may be omitted between
133 This is the second. Blank lines may be omitted between
132 options (as above) or left in (as here).
134 options (as above) or left in (as here).
135
133
136
134 The next paragraph looks like an option list, but lacks the two-space
137 The next paragraph looks like an option list, but lacks the two-space
135 marker after the option. It is treated as a normal paragraph:
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 There is support for simple option lists, but only with long
180 There is support for simple option lists, but only with long
181 options:
181 options:
182
182
183 --all Output all.
183 -X --exclude filter an option with a short and long option
184 --both Output both (this description is quite long).
184 with an argument
185 --long Output all day long.
185 -I --include an option with both a short option and
186 --par This option has two paragraphs in its
186 a long option
187 description. This is the first.
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
194 This is the second. Blank lines may
190 between options (as above) or left in (as here).
195 be omitted between options (as above)
196 or left in (as here).
191
197
192 The next paragraph looks like an option list, but lacks the
198 The next paragraph looks like an option list, but lacks the
193 two-space marker after the option. It is treated as a normal
199 two-space marker after the option. It is treated as a normal
@@ -202,23 +208,62 b' There is support for simple'
202 option lists, but only with
208 option lists, but only with
203 long options:
209 long options:
204
210
205 --all Output all.
211 -X --exclude filter an
206 --both Output both (this
212 option
207 description is
213 with a
208 quite long).
214 short
209 --long Output all day
215 and
210 long.
216 long
211 --par This option has two
217 option
212 paragraphs in its
218 with an
213 description. This
219 argumen
214 is the first.
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.
253 This is
217 Blank lines may be
254 the
218 omitted between
255 second.
219 options (as above)
256 Blank
220 or left in (as
257 lines
221 here).
258 may be
259 omitted
260 between
261 options
262 (as
263 above)
264 or left
265 in (as
266 here).
222
267
223 The next paragraph looks like
268 The next paragraph looks like
224 an option list, but lacks the
269 an option list, but lacks the
General Comments 0
You need to be logged in to leave comments. Login now