fediverse/fep
37
268
Fork
You've already forked fep
100

escape html characters in clean_markdown #868

Merged
silverpill merged 1 commit from :patch-1 into main 2026年06月27日 17:34:17 +02:00
Contributor
Copy link

The site page for 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)

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)
escape html characters in clean_markdown
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
4ca4cdbe47
Using the built-in `html.escape()` since `nh3.escape()` is too
aggressive

Is it a duplicate of #825 ?

Is it a duplicate of https://codeberg.org/fediverse/fep/pulls/825 ?
Author
Contributor
Copy link

Escaping double quotes with a backslash fixes the YAML issue (like the PR that you linked), but the double quotes still need to be escaped before being used as an HTML attribute (<meta name="description" content="...">).

html.escape() fixes both the HTML and YAML double quote issue, while also handling other characters (&, <, >, ') that could cause issues.

if you want to keep the changes minimal, something like this should work as well:

transformed = transformed.replace('"', '&quot;')
Escaping double quotes with a backslash fixes the YAML issue (like the PR that you linked), but the double quotes still need to be escaped before being used as an HTML attribute (`<meta name="description" content="...">)`. `html.escape()` fixes both the HTML and YAML double quote issue, while also handling other characters (`&`, `<`, `>`, `'`) that could cause issues. if you want to keep the changes minimal, something like this should work as well: ```py transformed = transformed.replace('"', '&quot;') ```

Thanks for clarification, I agree that switching to html.escape() is a good idea.

I decided to merge #825 first, could you rebase this PR?

Thanks for clarification, I agree that switching to `html.escape()` is a good idea. I decided to merge https://codeberg.org/fediverse/fep/pulls/825 first, could you rebase this PR?
tcyrus force-pushed patch-1 from 4ca4cdbe47
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
to bcb6702c5c
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
2026年06月26日 23:55:46 +02:00
Compare
tcyrus deleted branch patch-1 2026年06月30日 00:27:10 +02:00
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
fediverse/fep!868
Reference in a new issue
fediverse/fep
No description provided.
Delete branch ":patch-1"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?