mdpo.text module
Text utilities for mdpo.
- mdpo.text.and_join(values)
Comma and space join using “and” between the last and penultimate items.
- Parameters:
values (list) – Values to join.
- mdpo.text.min_not_max_chars_in_a_row(char, text, default=1)
Return minimum possible of characters not found in a row for a string.
For example, given the string
"c cc cccc"
and the character"c"
, returns the minimum number of characters in a row that are not found, so3
in this case.This function is used in the source code to compute the string that wraps markdown code spans. Given the code span
"code that contains 3 \`\`\` and 2 \`\` backticks"
and the character"`"
, this function returns1
.
- mdpo.text.parse_escaped_pair(value, separator=':')
Escapes a pair key-value separated by a character.
The separator can be escaped using the character ‘'.
- Parameters:
- Raises:
ValueError – The value doesn’t contains an unescaped valid separator.
- Returns:
Parsed key-value pair.
- Return type:
- mdpo.text.parse_escaped_pairs(pairs, separator=':')
Escapes multiples pairs key-value separated by a character.
The separator can be escaped using the character ‘'.
- Parameters:
- Raises:
ValueError – A value doesn’t contains an unescaped valid separator.
KeyError – Repeated keys in pairs.
- Returns:
Key-value pairs.
- Return type: