Mercurial > hg
comparison mercurial/minirst.py @ 37084:f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
This might conflict with other patches floating around, sorry.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 22 Mar 2018 21:56:20 +0900 |
parents | e178fcaa3933 |
children | a61583cba509 |
comparison
equal
deleted
inserted
replaced
37083:f99d64e8a4e4 | 37084:f0b6fbea00cf |
---|---|
25 from .i18n import _ | 25 from .i18n import _ |
26 from . import ( | 26 from . import ( |
27 encoding, | 27 encoding, |
28 pycompat, | 28 pycompat, |
29 url, | 29 url, |
30 util, | 30 ) |
31 from .utils import ( | |
32 stringutil, | |
31 ) | 33 ) |
32 | 34 |
33 def section(s): | 35 def section(s): |
34 return "%s\n%s\n\n" % (s, "\"" * encoding.colwidth(s)) | 36 return "%s\n%s\n\n" % (s, "\"" * encoding.colwidth(s)) |
35 | 37 |
457 colwidth = encoding.colwidth(block['optstr']) | 459 colwidth = encoding.colwidth(block['optstr']) |
458 usablewidth = width - 1 | 460 usablewidth = width - 1 |
459 hanging = block['optstrwidth'] | 461 hanging = block['optstrwidth'] |
460 initindent = '%s%s ' % (block['optstr'], ' ' * ((hanging - colwidth))) | 462 initindent = '%s%s ' % (block['optstr'], ' ' * ((hanging - colwidth))) |
461 hangindent = ' ' * (encoding.colwidth(initindent) + 1) | 463 hangindent = ' ' * (encoding.colwidth(initindent) + 1) |
462 return ' %s\n' % (util.wrap(desc, usablewidth, | 464 return ' %s\n' % (stringutil.wrap(desc, usablewidth, |
463 initindent=initindent, | 465 initindent=initindent, |
464 hangindent=hangindent)) | 466 hangindent=hangindent)) |
465 | 467 |
466 def formatblock(block, width): | 468 def formatblock(block, width): |
467 """Format a block according to width.""" | 469 """Format a block according to width.""" |
468 if width <= 0: | 470 if width <= 0: |
469 width = 78 | 471 width = 78 |
475 hang = len(block['lines'][-1]) - len(block['lines'][-1].lstrip()) | 477 hang = len(block['lines'][-1]) - len(block['lines'][-1].lstrip()) |
476 | 478 |
477 defindent = indent + hang * ' ' | 479 defindent = indent + hang * ' ' |
478 text = ' '.join(map(bytes.strip, block['lines'])) | 480 text = ' '.join(map(bytes.strip, block['lines'])) |
479 return '%s\n%s\n' % (indent + admonition, | 481 return '%s\n%s\n' % (indent + admonition, |
480 util.wrap(text, width=width, | 482 stringutil.wrap(text, width=width, |
481 initindent=defindent, | 483 initindent=defindent, |
482 hangindent=defindent)) | 484 hangindent=defindent)) |
483 if block['type'] == 'margin': | 485 if block['type'] == 'margin': |
484 return '\n' | 486 return '\n' |
485 if block['type'] == 'literal': | 487 if block['type'] == 'literal': |
486 indent += ' ' | 488 indent += ' ' |
487 return indent + ('\n' + indent).join(block['lines']) + '\n' | 489 return indent + ('\n' + indent).join(block['lines']) + '\n' |
501 l = [] | 503 l = [] |
502 for w, v in zip(widths, row): | 504 for w, v in zip(widths, row): |
503 pad = ' ' * (w - encoding.colwidth(v)) | 505 pad = ' ' * (w - encoding.colwidth(v)) |
504 l.append(v + pad) | 506 l.append(v + pad) |
505 l = ' '.join(l) | 507 l = ' '.join(l) |
506 l = util.wrap(l, width=width, initindent=indent, hangindent=hang) | 508 l = stringutil.wrap(l, width=width, |
509 initindent=indent, | |
510 hangindent=hang) | |
507 if not text and block['header']: | 511 if not text and block['header']: |
508 text = l + '\n' + indent + '-' * (min(width, span)) + '\n' | 512 text = l + '\n' + indent + '-' * (min(width, span)) + '\n' |
509 else: | 513 else: |
510 text += l + "\n" | 514 text += l + "\n" |
511 return text | 515 return text |
512 if block['type'] == 'definition': | 516 if block['type'] == 'definition': |
513 term = indent + block['lines'][0] | 517 term = indent + block['lines'][0] |
514 hang = len(block['lines'][-1]) - len(block['lines'][-1].lstrip()) | 518 hang = len(block['lines'][-1]) - len(block['lines'][-1].lstrip()) |
515 defindent = indent + hang * ' ' | 519 defindent = indent + hang * ' ' |
516 text = ' '.join(map(bytes.strip, block['lines'][1:])) | 520 text = ' '.join(map(bytes.strip, block['lines'][1:])) |
517 return '%s\n%s\n' % (term, util.wrap(text, width=width, | 521 return '%s\n%s\n' % (term, stringutil.wrap(text, width=width, |
518 initindent=defindent, | 522 initindent=defindent, |
519 hangindent=defindent)) | 523 hangindent=defindent)) |
520 subindent = indent | 524 subindent = indent |
521 if block['type'] == 'bullet': | 525 if block['type'] == 'bullet': |
522 if block['lines'][0].startswith('| '): | 526 if block['lines'][0].startswith('| '): |
523 # Remove bullet for line blocks and add no extra | 527 # Remove bullet for line blocks and add no extra |
524 # indentation. | 528 # indentation. |
538 block['lines'][0] = key + block['lines'][0] | 542 block['lines'][0] = key + block['lines'][0] |
539 elif block['type'] == 'option': | 543 elif block['type'] == 'option': |
540 return formatoption(block, width) | 544 return formatoption(block, width) |
541 | 545 |
542 text = ' '.join(map(bytes.strip, block['lines'])) | 546 text = ' '.join(map(bytes.strip, block['lines'])) |
543 return util.wrap(text, width=width, | 547 return stringutil.wrap(text, width=width, |
544 initindent=indent, | 548 initindent=indent, |
545 hangindent=subindent) + '\n' | 549 hangindent=subindent) + '\n' |
546 | 550 |
547 def formathtml(blocks): | 551 def formathtml(blocks): |
548 """Format RST blocks as HTML""" | 552 """Format RST blocks as HTML""" |
549 | 553 |
550 out = [] | 554 out = [] |