##// END OF EJS Templates
minirst: end all blocks with newlines...
Matt Mackall -
r15125:bdc59505 default
parent child Browse files
Show More
@@ -2782,7 +2782,7 b' def help_(ui, name=None, unknowncmd=Fals'
2782 2782 doc = doc.splitlines()[0]
2783 2783 keep = ui.verbose and ['verbose'] or []
2784 2784 formatted, pruned = minirst.format(doc, textwidth, keep=keep)
2785 ui.write("\n%s\n" % formatted)
2785 ui.write("\n%s" % formatted)
2786 2786 if pruned:
2787 2787 ui.write(_('\nuse "hg -v help %s" to show verbose help\n') % name)
2788 2788
@@ -2862,7 +2862,7 b' def help_(ui, name=None, unknowncmd=Fals'
2862 2862 doc = doc()
2863 2863
2864 2864 ui.write("%s\n\n" % header)
2865 ui.write("%s\n" % minirst.format(doc, textwidth, indent=4))
2865 ui.write("%s" % minirst.format(doc, textwidth, indent=4))
2866 2866 try:
2867 2867 cmdutil.findcmd(name, table)
2868 2868 ui.write(_('\nuse "hg help -c %s" to see help for '
@@ -2887,7 +2887,7 b' def help_(ui, name=None, unknowncmd=Fals'
2887 2887 ui.write(_('%s extension - %s\n\n') % (name.split('.')[-1], head))
2888 2888 if tail:
2889 2889 ui.write(minirst.format(tail, textwidth))
2890 ui.status('\n\n')
2890 ui.status('\n')
2891 2891
2892 2892 if mod:
2893 2893 try:
@@ -2907,7 +2907,7 b' def help_(ui, name=None, unknowncmd=Fals'
2907 2907 msg = help.listexts(_("'%s' is provided by the following "
2908 2908 "extension:") % cmd, {ext: doc}, indent=4)
2909 2909 ui.write(minirst.format(msg, textwidth))
2910 ui.write('\n\n')
2910 ui.write('\n')
2911 2911 ui.write(_('use "hg help extensions" for information on enabling '
2912 2912 'extensions\n'))
2913 2913
@@ -2946,7 +2946,7 b' def help_(ui, name=None, unknowncmd=Fals'
2946 2946 if name != 'shortlist':
2947 2947 text = help.listexts(_('enabled extensions:'), extensions.enabled())
2948 2948 if text:
2949 ui.write("\n%s\n" % minirst.format(text, textwidth))
2949 ui.write("\n%s" % minirst.format(text, textwidth))
2950 2950
2951 2951 if not name:
2952 2952 ui.write(_("\nadditional help topics:\n\n"))
@@ -398,7 +398,7 b' def formatoption(block, width):'
398 398 hanging = block['optstrwidth']
399 399 initindent = '%s%s ' % (block['optstr'], ' ' * ((hanging - colwidth)))
400 400 hangindent = ' ' * (encoding.colwidth(initindent) + 1)
401 return ' %s' % (util.wrap(desc, usablewidth,
401 return ' %s\n' % (util.wrap(desc, usablewidth,
402 402 initindent=initindent,
403 403 hangindent=hangindent))
404 404
@@ -413,17 +413,18 b' def formatblock(block, width):'
413 413
414 414 defindent = indent + hang * ' '
415 415 text = ' '.join(map(str.strip, block['lines']))
416 return '%s\n%s' % (indent + admonition, util.wrap(text, width=width,
417 initindent=defindent,
418 hangindent=defindent))
416 return '%s\n%s\n' % (indent + admonition,
417 util.wrap(text, width=width,
418 initindent=defindent,
419 hangindent=defindent))
419 420 if block['type'] == 'margin':
420 return ''
421 return '\n'
421 422 if block['type'] == 'literal':
422 423 indent += ' '
423 return indent + ('\n' + indent).join(block['lines'])
424 return indent + ('\n' + indent).join(block['lines']) + '\n'
424 425 if block['type'] == 'section':
425 426 underline = encoding.colwidth(block['lines'][0]) * block['underline']
426 return "%s%s\n%s%s" % (indent, block['lines'][0],indent, underline)
427 return "%s%s\n%s%s\n" % (indent, block['lines'][0],indent, underline)
427 428 if block['type'] == 'table':
428 429 table = block['table']
429 430 # compute column widths
@@ -447,9 +448,9 b' def formatblock(block, width):'
447 448 hang = len(block['lines'][-1]) - len(block['lines'][-1].lstrip())
448 449 defindent = indent + hang * ' '
449 450 text = ' '.join(map(str.strip, block['lines'][1:]))
450 return '%s\n%s' % (term, util.wrap(text, width=width,
451 initindent=defindent,
452 hangindent=defindent))
451 return '%s\n%s\n' % (term, util.wrap(text, width=width,
452 initindent=defindent,
453 hangindent=defindent))
453 454 subindent = indent
454 455 if block['type'] == 'bullet':
455 456 if block['lines'][0].startswith('| '):
@@ -481,7 +482,7 b' def formatblock(block, width):'
481 482 text = ' '.join(map(str.strip, block['lines']))
482 483 return util.wrap(text, width=width,
483 484 initindent=indent,
484 hangindent=subindent)
485 hangindent=subindent) + '\n'
485 486
486 487 def parse(text, indent=0, keep=None):
487 488 """Parse text into a list of blocks"""
@@ -504,13 +505,13 b' def parse(text, indent=0, keep=None):'
504 505 return blocks, pruned
505 506
506 507 def formatblocks(blocks, width):
507 text = '\n'.join(formatblock(b, width) for b in blocks)
508 text = ''.join(formatblock(b, width) for b in blocks)
508 509 return text
509 510
510 511 def format(text, width, indent=0, keep=None):
511 512 """Parse and format the text according to width."""
512 513 blocks, pruned = parse(text, indent, keep or [])
513 text = '\n'.join(formatblock(b, width) for b in blocks)
514 text = ''.join(formatblock(b, width) for b in blocks)
514 515 if keep is None:
515 516 return text
516 517 else:
@@ -6,6 +6,7 b' This is some text in the first paragraph'
6 6 containing random whitespace.
7 7
8 8 The third and final paragraph.
9
9 10 ----------------------------------------------------------------------
10 11
11 12 paragraphs formatted to fit within 30 characters:
@@ -19,6 +20,7 b' paragraph.'
19 20 whitespace.
20 21
21 22 The third and final paragraph.
23
22 24 ----------------------------------------------------------------------
23 25
24 26 definitions formatted to fit within 60 characters:
@@ -33,6 +35,7 b' Another Term'
33 35
34 36 A Nested/Indented Term
35 37 Definition.
38
36 39 ----------------------------------------------------------------------
37 40
38 41 definitions formatted to fit within 30 characters:
@@ -52,6 +55,7 b' Another Term'
52 55
53 56 A Nested/Indented Term
54 57 Definition.
58
55 59 ----------------------------------------------------------------------
56 60
57 61 literals formatted to fit within 60 characters:
@@ -72,6 +76,7 b' space-double-colon.'
72 76 This literal block is started with '::',
73 77 the so-called expanded form. The paragraph
74 78 with '::' disappears in the final output.
79
75 80 ----------------------------------------------------------------------
76 81
77 82 literals formatted to fit within 30 characters:
@@ -94,6 +99,7 b' with space-double-colon.'
94 99 This literal block is started with '::',
95 100 the so-called expanded form. The paragraph
96 101 with '::' disappears in the final output.
102
97 103 ----------------------------------------------------------------------
98 104
99 105 lists formatted to fit within 60 characters:
@@ -129,6 +135,7 b' Line blocks are also a form of list:'
129 135
130 136 This is the first line. The line continues here.
131 137 This is the second line.
138
132 139 ----------------------------------------------------------------------
133 140
134 141 lists formatted to fit within 30 characters:
@@ -173,6 +180,7 b' list:'
173 180 This is the first line. The
174 181 line continues here.
175 182 This is the second line.
183
176 184 ----------------------------------------------------------------------
177 185
178 186 options formatted to fit within 60 characters:
@@ -200,6 +208,7 b' two-space marker after the option. It is'
200 208 paragraph:
201 209
202 210 --foo bar baz
211
203 212 ----------------------------------------------------------------------
204 213
205 214 options formatted to fit within 30 characters:
@@ -272,6 +281,7 b' option. It is treated as a'
272 281 normal paragraph:
273 282
274 283 --foo bar baz
284
275 285 ----------------------------------------------------------------------
276 286
277 287 fields formatted to fit within 60 characters:
@@ -286,6 +296,7 b' small The larger key below trigger'
286 296 here.
287 297 much too large
288 298 This key is big enough to get its own line.
299
289 300 ----------------------------------------------------------------------
290 301
291 302 fields formatted to fit within 30 characters:
@@ -305,11 +316,13 b' much too large'
305 316 This key is big
306 317 enough to get its
307 318 own line.
319
308 320 ----------------------------------------------------------------------
309 321
310 322 containers (normal) formatted to fit within 60 characters:
311 323 ----------------------------------------------------------------------
312 324 Normal output.
325
313 326 ----------------------------------------------------------------------
314 327
315 328 containers (verbose) formatted to fit within 60 characters:
@@ -317,6 +330,7 b' containers (verbose) formatted to fit wi'
317 330 Normal output.
318 331
319 332 Verbose output.
333
320 334 ----------------------------------------------------------------------
321 335 ['debug', 'debug']
322 336 ----------------------------------------------------------------------
@@ -326,6 +340,7 b' containers (debug) formatted to fit with'
326 340 Normal output.
327 341
328 342 Initial debug output.
343
329 344 ----------------------------------------------------------------------
330 345 ['verbose']
331 346 ----------------------------------------------------------------------
@@ -339,6 +354,7 b' Initial debug output.'
339 354 Verbose output.
340 355
341 356 Debug output.
357
342 358 ----------------------------------------------------------------------
343 359 []
344 360 ----------------------------------------------------------------------
@@ -346,6 +362,7 b' Debug output.'
346 362 roles formatted to fit within 60 characters:
347 363 ----------------------------------------------------------------------
348 364 Please see "hg add".
365
349 366 ----------------------------------------------------------------------
350 367
351 368 sections formatted to fit within 20 characters:
@@ -361,6 +378,7 b' Subsection'
361 378
362 379 Markup: "foo" and "hg help"
363 380 ---------------------------
381
364 382 ----------------------------------------------------------------------
365 383
366 384 admonitions formatted to fit within 30 characters:
@@ -377,6 +395,7 b' Note:'
377 395
378 396 !Danger!
379 397 This is danger
398
380 399 ----------------------------------------------------------------------
381 400
382 401 comments formatted to fit within 30 characters:
@@ -386,6 +405,7 b' Some text.'
386 405 Some indented text.
387 406
388 407 Empty comment above
408
389 409 ----------------------------------------------------------------------
390 410
391 411 === === ========================================
General Comments 0
You need to be logged in to leave comments. Login now