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, so 3 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 returns 1.

Parameters:
  • char (str) – Character to search.

  • text (str) – Text inside which find the character repeated in a row.

  • default (int) – Default value to return if the character is not found.

Returns:

Minimum number possible of characters not found in a row.

Return type:

int

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:
  • value (str) – String to be converted to a pair key-value.

  • separator (str) – Separator to use for the split.

Raises:

ValueError – The value doesn’t contains an unescaped valid separator.

Returns:

Parsed key-value pair.

Return type:

tuple

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:
  • pairs (list) – List of texts to parse.

  • separator (str) – Separator to use for the splits.

Raises:
  • ValueError – A value doesn’t contains an unescaped valid separator.

  • KeyError – Repeated keys in pairs.

Returns:

Key-value pairs.

Return type:

dict

mdpo.text.parse_strint_0_inf(value)

Parse a string to a integer accepting infinte values.

Converts an integer passed as string in an integer or math.inf if the passed value is "0" or math.inf.

Parameters:

value (str) – Value to parse.

mdpo.text.parse_wrapwidth_argument(value)

Parse the argument -w/--wrapwidth.

Parameters:

value (str) – Wrapwidth value.