From deae30c65f457cb461064a0b2e584139bbdfb0ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Mee=C3=9Fen?= Date: Mon, 25 Jul 2022 13:31:39 +0200 Subject: [PATCH 1/2] wip: removing line breaks --- main.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index a6787b6..f403230 100755 --- a/main.py +++ b/main.py @@ -64,7 +64,13 @@ def get_md_without_front_matter(file): # Parse to remove html tags md_parser = parser.SvHtmlParser() md_parser.feed(raw_markdown) - return md_parser.close().to_markdown() + + md_parsed = md_parser.close().to_markdown() + + # Remove single line breaks which should not be rendered + md_final = re.sub(r'(?<=[\w., ])(\n)(?=[\w., ])', ' ', md_parsed) + + return md_final def get_spotlights(): From 0df60e5674cd9d9cba83f0ba7c8b67ac522a2a5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Mee=C3=9Fen?= Date: Tue, 26 Jul 2022 14:43:53 +0200 Subject: [PATCH 2/2] Remove line breaks in paragraphs --- main.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index f403230..3760b9e 100755 --- a/main.py +++ b/main.py @@ -67,10 +67,21 @@ def get_md_without_front_matter(file): md_parsed = md_parser.close().to_markdown() - # Remove single line breaks which should not be rendered - md_final = re.sub(r'(?<=[\w., ])(\n)(?=[\w., ])', ' ', md_parsed) + # Now split by code blocks + md_split = md_parsed.split(r"```") + if len(md_split) % 2 == 0: + raise Exception( + "There was an error parsing markdown code blocks in %s" % file + ) + + # Remove line breaks inside paragraphs, because they would be rendered as
+ # Only every scond block, because we do not want to replace newlines in code blocks + for i in range(0, len(md_split), 2): + md_split[i] = re.sub( + r"(?<=[\w., \(\)\[\]])(\n)(?=[\w., \(\)\[\]])", " ", md_split[i] + ) - return md_final + return "```".join(md_split) def get_spotlights():