From f395209d87b55a5df0c905221683e8d8d0d8cca0 Mon Sep 17 00:00:00 2001 From: YuviPanda Date: Sun, 17 Dec 2023 21:40:08 -0800 Subject: [PATCH] Add table, td, tr to allowed list of tags 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 https://github.com/jupyter/nbconvert/pull/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 https://github.com/jupyter/nbconvert/pull/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 (https://github.com/jupyter/nbconvert/issues/1892), but this is a small and focused change so hopefully doesn't need to block on --- nbconvert/filters/strings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nbconvert/filters/strings.py b/nbconvert/filters/strings.py index 9284521ef..81a0453ad 100644 --- a/nbconvert/filters/strings.py +++ b/nbconvert/filters/strings.py @@ -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"],