Skip to content

Commit

Permalink
Add table, td, tr to allowed list of tags
Browse files Browse the repository at this point in the history
pygments emits line numbers via tables, with tr and td
elements (https://pygments.org/docs/formatters/#HtmlFormatter).
lxml's clean_html considers table, tr and td as safe elements,
but with jupyter#1854 they
are now considered unsafe. So instead of displaying line numbers,
the table, tr and td elements are escaped, and show up as literal
HTML if trying to enable line numbers via the method introduced
in jupyter#1683.

This PR adds table, tr and td as safe elements so that line numbers
can continue to work.

I know that there are probably plans to move away from bleach
(jupyter#1892), but this is
a small and focused change so hopefully doesn't need to block on
  • Loading branch information
yuvipanda committed Dec 18, 2023
1 parent a7df9af commit f395209
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion nbconvert/filters/strings.py
Expand Up @@ -89,7 +89,7 @@ def clean_html(element):
kwargs["css_sanitizer"] = css_sanitizer
return bleach.clean(
element,
tags=[*bleach.ALLOWED_TAGS, "div", "pre", "code", "span"],
tags=[*bleach.ALLOWED_TAGS, "div", "pre", "code", "span", "table", "tr", "td"],
attributes={
**bleach.ALLOWED_ATTRIBUTES,
"*": ["class", "id"],
Expand Down

0 comments on commit f395209

Please sign in to comment.