Return a formatted text wrapped at `width` given an iterable of tokens. None tokens for unmatched positions are replaced with `no_match`.
(tokens, width=80, margin=4)
| 37 | |
| 38 | |
| 39 | def format_text(tokens, width=80, margin=4): |
| 40 | """ |
| 41 | Return a formatted text wrapped at `width` given an iterable of tokens. |
| 42 | None tokens for unmatched positions are replaced with `no_match`. |
| 43 | """ |
| 44 | noop = lambda x: [x] |
| 45 | initial_indent = subsequent_indent = u' ' * margin |
| 46 | wrapper = partial(textwrap.wrap, |
| 47 | width=width, |
| 48 | break_on_hyphens=False, |
| 49 | initial_indent=initial_indent, |
| 50 | subsequent_indent=subsequent_indent) |
| 51 | wrap = width and wrapper or noop |
| 52 | return u'\n'.join(wrap(u' '.join(tokens))) |
| 53 | |
| 54 | |
| 55 | def matched_rule_tokens_str(match): |