Module pl.text
Text processing utilities.
This provides a Template class (modeled after the same from the Python
libraries, see string.Template). It also provides dedent, wrap and fill as found in the textwrap module, as well as indent.
Functions
Template:indent_substitute (tbl) | substitute values into a template, preserving indentation. |
Template:safe_substitute (tbl) | substitute values into a template. |
Template:substitute (tbl) | substitute values into a template, throwing an error. |
dedent (s) | dedent a multiline string by removing any initial indent. |
fill (s, width) | format a paragraph so that it fits into a line width. |
indent (s, n, ch) | indent a multiline string. |
wrap (s, width) | format a paragraph into lines so that they fit into a line width. |
Functions
- Template:indent_substitute (tbl)
-
substitute values into a template, preserving indentation.
If the value is a multiline string _or_ a template, it will insert the lines at the correct indentation.
Furthermore, if a template, then that template will be subsituted using the same table.Parameters:
-
tbl
: a table of name-value pairs.
-
- Template:safe_substitute (tbl)
-
substitute values into a template. This version just passes unknown names through.
Parameters:
-
tbl
: a table of name-value pairs.
-
- Template:substitute (tbl)
-
substitute values into a template, throwing an error. This will throw an error if no name is found.
Parameters:
-
tbl
: a table of name-value pairs.
-
- dedent (s)
-
dedent a multiline string by removing any initial indent. useful when working with [[..]] strings.
Parameters:
-
s
: the string
Return value:
- a string with initial indent zero.
-
- fill (s, width)
-
format a paragraph so that it fits into a line width.
Parameters:
-
s
: the string -
width
: the margin width, default 70
Return value:
- a string
See also:
-
- indent (s, n, ch)
-
indent a multiline string.
Parameters:
-
s
: the string -
n
: the size of the indent -
ch
: the character to use when indenting (default ' ')
Return value:
- indented string
-
- wrap (s, width)
-
format a paragraph into lines so that they fit into a line width. It will not break long words, so lines can be over the length to that extent.
Parameters:
-
s
: the string -
width
: the margin width, default 70
Return value:
- a list of lines
-