Source code for semantic_release.commit_parser.util
from__future__importannotationsfromfunctoolsimportreducefromreimportcompileasregexpfromtypingimportTYPE_CHECKINGifTYPE_CHECKING:fromreimportPatternfromtypingimportTypedDictclassRegexReplaceDef(TypedDict):pattern:Patternrepl:strbreaking_re=regexp(r"BREAKING[ -]CHANGE:\s?(.*)")un_word_wrap:RegexReplaceDef={# Match a line ending where the next line is not indented, or a bullet"pattern":regexp(r"((?<!-)\n(?![\s*-]))"),"repl":r" ",# Replace with a space}un_word_wrap_hyphen:RegexReplaceDef={"pattern":regexp(r"((?<=\w)-\n(?=\w))"),"repl":r"-",# Replace with single hyphen}trim_line_endings:RegexReplaceDef={# Match line endings with optional whitespace"pattern":regexp(r"[\r\t\f\v ]*\r?\n"),"repl":"\n",# remove the optional whitespace & remove windows newlines}
[docs]defparse_paragraphs(text:str)->list[str]:r""" This will take a text block and return a list containing each paragraph with single line breaks collapsed into spaces. To handle Windows line endings, carriage returns '\r' are removed before separating into paragraphs. :param text: The text string to be divided. :return: A list of condensed paragraphs, as strings. """adjusted_text=reduce(lambdatxt,adj:adj["pattern"].sub(adj["repl"],txt),[trim_line_endings,un_word_wrap_hyphen],text,)returnlist(filter(None,[un_word_wrap["pattern"].sub(un_word_wrap["repl"],paragraph).strip()forparagraphinadjusted_text.split("\n\n")],))