1
0
mirror of https://codeberg.org/fediverse/fep.git synced 2026-08-08 13:35:51 +00:00

escape html characters in clean_markdown (#868)

The site page for [FEP-61cf](https://fediverse.codeberg.page/fep/fep/61cf/) is currently bugged because of unescaped double quotes.
The YAML issue could be solved with something like `yaml.safe_dump`, but there's also an HTML issue (mkdocs doesn't escape quotes).
`clean_markdown` now uses the built-in `html.escape()` (`nh3.escape()` escapes too much)

Reviewed-on: https://codeberg.org/fediverse/fep/pulls/868
This commit is contained in:
Timothy Cyrus
2026-06-27 17:33:50 +02:00
committed by silverpill
parent 7acaa11a4c
commit 7eefb5cf57
+3 -2
View File
@@ -1,3 +1,4 @@
import html
import re
import shutil
from pathlib import Path
@@ -57,8 +58,8 @@ def clean_markdown(text: str) -> str:
"""Transforms markdown to a plain text string. To be used in the frontmatter"""
transformed = nh3.clean(markdown(text), tags=set())
transformed = re.sub(r"\[(.+?)\]\[(.+?)\]", r"\1", transformed)
# Escape double quotes (FEP-db0e, FEP-7b29)
transformed = transformed.replace('"', '\\"')
# Escape HTML special characters (FEP-db0e, FEP-7b29)
transformed = html.escape(transformed)
return transformed.replace("\n", " ")