fix: indent and remove empty <p>

This commit is contained in:
2025-07-08 22:05:41 +02:00
parent cf9cd77bcf
commit e1f08f0312

View File

@ -4,6 +4,8 @@ from collections.abc import Callable
from . import default_converters from . import default_converters
from bs4 import BeautifulSoup
class Bozodown(): class Bozodown():
def __init__(self): def __init__(self):
@ -19,7 +21,7 @@ class Bozodown():
text, converter = self._get_first_converter(to_parse) text, converter = self._get_first_converter(to_parse)
content += self._render_element(text, converter) content += self._render_element(text, converter)
to_parse = to_parse[len(text):] to_parse = to_parse[len(text):]
return content return BeautifulSoup(content, 'html.parser').prettify()
def _render_element(self, text: str, converter: dict[str, str]) -> str: def _render_element(self, text: str, converter: dict[str, str]) -> str:
@ -30,6 +32,8 @@ class Bozodown():
return func(id, text) return func(id, text)
start: int = len(converter["from_prefix"]) start: int = len(converter["from_prefix"])
stop: int = len(text) - len(converter.get("from_suffix", "")) stop: int = len(text) - len(converter.get("from_suffix", ""))
if (text[start:stop] == "\n" and converter is self._text_converter):
return ""
return f"{converter['to_prefix']}{text[start:stop]}{converter['to_suffix']}" return f"{converter['to_prefix']}{text[start:stop]}{converter['to_suffix']}"
def _bozodown_render(self, id: str, text: str) -> str: def _bozodown_render(self, id: str, text: str) -> str: