Skip to content
Snippets Groups Projects
Commit 8b2d051b authored by Andreas Kraft's avatar Andreas Kraft
Browse files

Made <br> replacement a bit more flexible. Also, ignoring code blocks

parent 96613f89
No related branches found
No related tags found
No related merge requests found
......@@ -132,14 +132,23 @@ def replaceLineBreaks(progress: Progress, mdLines: list[str]) -> list[str]:
"""
_taskID = progress.add_task('[blue]Replacing linebreaks', start=False, total=0)
# progress.update()
linebreaksregex = re.compile('<br />')
linebreaksregex = re.compile('<br\s*/?\s*>')
_lines: list[str] = []
_inCodeBlock = False
for line in mdLines:
# Check if we are in a code block
if line.strip().startswith('```'):
_inCodeBlock = not _inCodeBlock
if _inCodeBlock:
_lines.append(line)
continue
# Replace linebreaks
matches = re.findall(linebreaksregex, line)
if matches:
# Replace the linebreak with "\(newline)"
_lines.append(re.sub(r'<br />', f'\\\n', line))
_lines.append(re.sub(linebreaksregex, f'\\\n', line))
else:
_lines.append(line)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment