diff --git a/legaltexts/cli.py b/legaltexts/cli.py
index 26aba17..2fb2ce9 100644
--- a/legaltexts/cli.py
+++ b/legaltexts/cli.py
@@ -166,6 +166,7 @@ def md_to_html_fragment(markdown: str)->str:
str(markdown_file),
'-t', 'html',
'-o', output_html,
+ '--wrap=preserve',
])
return output_html.read_text()
diff --git a/legaltexts/toc_generator.py b/legaltexts/toc_generator.py
index 2197514..5e8d905 100644
--- a/legaltexts/toc_generator.py
+++ b/legaltexts/toc_generator.py
@@ -15,7 +15,7 @@ def add_links_to_toc(html, text, target="#toc"):
>>> add_links_to_toc('
Titol
', text='Torna a dalt', target="#target")
''
"""
- soup = BeautifulSoup(html, features="html.parser")
+ soup = BeautifulSoup(html, features="html.parser", preserve_whitespace_tags={'p', 'li'})
headers = sum((
soup.find_all(f'h{l}')
for l in range(2,7)
@@ -24,7 +24,7 @@ def add_links_to_toc(html, text, target="#toc"):
uplink = BeautifulSoup(f" - ", features="html.parser")
uplink.find('a').string = text
header.append(uplink)
- return str(soup)
+ return soup.prettify(formatter=None)
def generate_toc(markdown_text, top_level=None, bottom_level=None, title=None):
"""