Skip to content

Commit

Permalink
✨ Preserve markdown lines in html
Browse files Browse the repository at this point in the history
This enables better diffing of the output
  • Loading branch information
vokimon committed Nov 8, 2024
1 parent b5b5e78 commit d6e3d11
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions legaltexts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions legaltexts/toc_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def add_links_to_toc(html, text, target="#toc"):
>>> add_links_to_toc('<h3>Titol</h3>', text='Torna a dalt', target="#target")
'<h3>Titol<span class="pujar"> - <a href="#target">Torna a dalt</a></span></h3>'
"""
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)
Expand All @@ -24,7 +24,7 @@ def add_links_to_toc(html, text, target="#toc"):
uplink = BeautifulSoup(f"<span class='pujar'> - <a href='{target}' /></span>", 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):
"""
Expand Down

0 comments on commit d6e3d11

Please sign in to comment.