Merge pull request 'Fixes for HTML stuff' (#153) from freamon/pyfedi:10 into main

Reviewed-on: https://codeberg.org/rimu/pyfedi/pulls/153
This commit is contained in:
rimu 2024-04-12 04:18:59 +00:00
commit 5e20658474

View file

@ -221,8 +221,8 @@ def markdown_to_html(markdown_text) -> str:
if markdown_text: if markdown_text:
raw_html = markdown2.markdown(markdown_text, safe_mode=True, extras={'middle-word-em': False, 'tables': True, 'fenced-code-blocks': True, 'strike': True}) raw_html = markdown2.markdown(markdown_text, safe_mode=True, extras={'middle-word-em': False, 'tables': True, 'fenced-code-blocks': True, 'strike': True})
# replace lemmy spoiler tokens with appropriate html tags instead. (until possibly added as extra to markdown2) # replace lemmy spoiler tokens with appropriate html tags instead. (until possibly added as extra to markdown2)
re_spoiler = re.compile(r':{3} spoiler\s+?(\S.+?\n)(.+?)\n:{3}', re.S) re_spoiler = re.compile(r':{3} spoiler\s+?(\S.+?)(?:\n|</p>)(.+?)(?:\n|<p>):{3}', re.S)
raw_html = re_spoiler.sub(r'<details><summary>\1</summary>\2</details>', raw_html) raw_html = re_spoiler.sub(r'<details><summary>\1</summary><p>\2</p></details>', raw_html)
return allowlist_html(raw_html) return allowlist_html(raw_html)
else: else:
return '' return ''
@ -245,6 +245,8 @@ def microblog_content_to_title(html: str) -> str:
continue continue
else: else:
tag = tag.extract() tag = tag.extract()
else:
tag = tag.extract()
if title_found: if title_found:
result = soup.text result = soup.text