diff options
| author | 2021-01-06 06:56:17 +0100 | |
|---|---|---|
| committer | 2021-01-09 20:11:15 +0100 | |
| commit | 003613ff0f89871c8477e996c708873e1387e514 (patch) | |
| tree | e5e77836ca78a7365c01bacdfd07afc59986624a | |
| parent | Use update_wrapper instead of wraps (diff) | |
Add comments to truncation handling code
Co-authored-by: MarkKoz <[email protected]>
| -rw-r--r-- | bot/exts/info/doc/_parsing.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/bot/exts/info/doc/_parsing.py b/bot/exts/info/doc/_parsing.py index 521034006..f51ab4ea1 100644 --- a/bot/exts/info/doc/_parsing.py +++ b/bot/exts/info/doc/_parsing.py @@ -276,15 +276,21 @@ def _get_truncated_description( if not markdown_element_ends: return "" + # Determine the "hard" truncation index. newline_truncate_index = find_nth_occurrence(result, "\n", max_lines) if newline_truncate_index is not None and newline_truncate_index < _MAX_DESCRIPTION_LENGTH: + # Truncate based on maximum lines if there are more than the maximum number of lines. truncate_index = newline_truncate_index else: + # There are less than the maximum number of lines; truncate based on the max char length. truncate_index = _MAX_DESCRIPTION_LENGTH + # Nothing needs to be truncated if the last element ends before the truncation index. if truncate_index >= markdown_element_ends[-1]: return result + # Determine the actual truncation index. + # Truncate at the last Markdown element that comes before the truncation index. markdown_truncate_index = max(cut for cut in markdown_element_ends if cut < truncate_index) return result[:markdown_truncate_index].strip(_TRUNCATE_STRIP_CHARACTERS) + "..." |