diff --git a/frontend/src/css/md.css b/frontend/src/css/md.css index 88639fe03f2..393b74f4e89 100644 --- a/frontend/src/css/md.css +++ b/frontend/src/css/md.css @@ -78,8 +78,14 @@ a .markdown iconify-icon:first-child { margin-inline-end: 0.4em; } +iconify-icon { + display: inline-flex; + align-items: center; +} + /* align icons with buttons better */ button .markdown .paragraph { + display: inline-flex; align-items: baseline; gap: 0.4em; diff --git a/frontend/src/plugins/core/__test__/sanitize.test.ts b/frontend/src/plugins/core/__test__/sanitize.test.ts index ab90e8a4b95..63329b91580 100644 --- a/frontend/src/plugins/core/__test__/sanitize.test.ts +++ b/frontend/src/plugins/core/__test__/sanitize.test.ts @@ -462,4 +462,31 @@ describe("sanitizeHtml", () => { `"
Click me

Hidden content

"`, ); }); + + test("preserves iconify-icon custom element", () => { + const html = ''; + expect(sanitizeHtml(html)).toMatchInlineSnapshot( + `""`, + ); + }); + + test("preserves iconify-icon with all attributes", () => { + const html = + ''; + expect(sanitizeHtml(html)).toMatchInlineSnapshot( + `""`, + ); + }); + + test("preserves self-closing iconify-icon", () => { + const html = ''; + expect(sanitizeHtml(html)).toMatchInlineSnapshot( + `""`, + ); + }); + + test("still removes other non-marimo/non-iconify custom elements", () => { + const html = "Content"; + expect(sanitizeHtml(html)).toMatchInlineSnapshot(`"Content"`); + }); }); diff --git a/frontend/src/plugins/core/sanitize.ts b/frontend/src/plugins/core/sanitize.ts index 348092eacba..79e3364c613 100644 --- a/frontend/src/plugins/core/sanitize.ts +++ b/frontend/src/plugins/core/sanitize.ts @@ -75,7 +75,7 @@ export function sanitizeHtml(html: string) { // glue elements like style, script or others to document.body and prevent unintuitive browser behavior in several edge-cases FORCE_BODY: true, CUSTOM_ELEMENT_HANDLING: { - tagNameCheck: /^marimo-[A-Za-z][\w-]*$/, + tagNameCheck: /^(marimo-[A-Za-z][\w-]*|iconify-icon)$/, attributeNameCheck: /^[A-Za-z][\w-]*$/, }, }; diff --git a/marimo/_smoke_tests/icons.py b/marimo/_smoke_tests/icons.py index eaae19777df..d03c6dbc55d 100644 --- a/marimo/_smoke_tests/icons.py +++ b/marimo/_smoke_tests/icons.py @@ -8,7 +8,7 @@ import marimo -__generated_with = "0.15.5" +__generated_with = "0.17.3" app = marimo.App() @@ -92,11 +92,7 @@ def _(mo): @app.cell def _(mo): - mo.md( - f""" - ## {mo.icon('material-symbols:edit')} Icons in markdown - """ - ) + mo.md(f"""## {mo.icon('material-symbols:edit')} Icons in markdown""") return