module documentation

Git stripspace functionality for cleaning up text and commit messages.

Function stripspace Strip unnecessary whitespace from text.
def stripspace(text: bytes, *, strip_comments: bool = False, comment_char: bytes = b'#', comment_lines: bool = False) -> bytes: ΒΆ

Strip unnecessary whitespace from text.

This function mimics the behavior of git stripspace, which is commonly used to clean up commit messages and other text content.

The function performs the following operations (in order):
  1. If comment_lines is True, prepend comment_char + space to each line
  2. Strip trailing whitespace from each line
  3. If strip_comments is True, remove lines starting with comment_char
  4. Collapse multiple consecutive blank lines into a single blank line
  5. Remove leading blank lines
  6. Remove trailing blank lines
  7. Ensure the text ends with a newline (unless empty)
Parameters
text:bytesThe text to process (as bytes)
strip_comments:boolIf True, remove lines that begin with comment_char
comment_char:bytesThe comment character to use (default: b"#")
comment_lines:boolIf True, prepend comment_char to each line
Returns
bytesThe processed text as bytes