diff --git a/main.py b/main.py index a6787b6..3760b9e 100755 --- a/main.py +++ b/main.py @@ -64,7 +64,24 @@ 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() + + # 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 "```".join(md_split) def get_spotlights():