Skip to content

Commit

Permalink
Merge pull request #6 from hifis-net/5-remove_linebreaks
Browse files Browse the repository at this point in the history
Remove line breaks in Markdown paragraphs
  • Loading branch information
cmeessen authored Jul 26, 2022
2 parents f7d6aed + 0df60e5 commit 8065375
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <br>
# 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():
Expand Down

0 comments on commit 8065375

Please sign in to comment.