init
This commit is contained in:
commit
38355d2442
9083 changed files with 1225834 additions and 0 deletions
38
.venv/lib/python3.8/site-packages/traitlets/utils/text.py
Normal file
38
.venv/lib/python3.8/site-packages/traitlets/utils/text.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
"""
|
||||
Utilities imported from ipython_genutils
|
||||
"""
|
||||
|
||||
import re
|
||||
from textwrap import dedent, indent as _indent
|
||||
import textwrap
|
||||
|
||||
|
||||
def indent(val):
|
||||
res = _indent(val, " ")
|
||||
return res
|
||||
|
||||
|
||||
def wrap_paragraphs(text: str, ncols=80):
|
||||
"""Wrap multiple paragraphs to fit a specified width.
|
||||
|
||||
This is equivalent to textwrap.wrap, but with support for multiple
|
||||
paragraphs, as separated by empty lines.
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
||||
list of complete paragraphs, wrapped to fill `ncols` columns.
|
||||
"""
|
||||
paragraph_re = re.compile(r"\n(\s*\n)+", re.MULTILINE)
|
||||
text = dedent(text).strip()
|
||||
paragraphs = paragraph_re.split(text)[::2] # every other entry is space
|
||||
out_ps = []
|
||||
indent_re = re.compile(r"\n\s+", re.MULTILINE)
|
||||
for p in paragraphs:
|
||||
# presume indentation that survives dedent is meaningful formatting,
|
||||
# so don't fill unless text is flush.
|
||||
if indent_re.search(p) is None:
|
||||
# wrap paragraph
|
||||
p = textwrap.fill(p, ncols)
|
||||
out_ps.append(p)
|
||||
return out_ps
|
||||
Loading…
Add table
Add a link
Reference in a new issue