Commit 8b2d051b authored by ankraft's avatar ankraft
Browse files

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

parent 96613f89
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -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)