Skip to content

fix: read font-family from inline style on HTML import#143

Merged
JohnMcLear merged 2 commits into
mainfrom
fix/import-style-font-family
May 9, 2026
Merged

fix: read font-family from inline style on HTML import#143
JohnMcLear merged 2 commits into
mainfrom
fix/import-style-font-family

Conversation

@JohnMcLear
Copy link
Copy Markdown
Member

Problem

ep_font_family stores the chosen font as a custom tag (<fontarial>...</fontarial>) on the pad side. getLineHTMLForExport rewrites those tags into the standard CSS form (<span style="font-family:arial">...</span>) on export. But the import side — tagAttribute.collectContentPre — only looks for the tag form.

Net effect: round-tripping any pad through HTML or DOCX silently loses the font, including DOCX export → import via ether/etherpad#7568's native path.

Fix

Wrap collectContentPre to also scan context.styl for font-family:.... Normalize the value back to one of the toolbar tag names (font + lowercase + spaces → hyphens), pick the first family in a fallback list, and handle quoted values ('Times New Roman'). monospace maps to fontmonospace; everything else falls through.

Tests

static/tests/backend/specs/exportHTML.ts: new file, three test cases asserting that a pad imported with <span style="font-family:<value>">styled</span> re-exports with the matching font tag/style. Covers Arial, 'Times New Roman', courier.

Refs ether/etherpad#7568. Sister PRs: ether/ep_align#183 (text-align, merged), ether/ep_font_color#150 (color), ether/ep_font_size#132 (font-size).

ep_font_family stores the font as a custom tag (<fontarial>...) but
its getLineHTMLForExport rewrites those tags into standard CSS
'<span style="font-family:arial">...</span>' on export. The import
side, via tagAttribute.collectContentPre, only looks for the tag
form -- so any round-trip through HTML or DOCX silently lost the
font.

Read 'font-family:...' from the inline style attribute (etherpad
core's contentcollector exposes context.styl), normalize the value
back to one of the toolbar tag names ('font' + lowercase + spaces
to hyphens), and apply the matching attribute. Handles quoted
values, the first font in a fallback list, and 'monospace' as a
generic family.

Refs ether/etherpad#7568. Sister PRs: ep_align#183 (text-align,
merged), ep_font_color#150, ep_font_size#132.

Tests added: round-trip via 'style="font-family:<value>"' for
Arial, 'Times New Roman', courier.
@qodo-code-review
Copy link
Copy Markdown

ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one.

Comment thread static/tests/backend/specs/exportHTML.ts Fixed
Comment thread static/tests/backend/specs/exportHTML.ts Fixed
CodeQL flagged the unused destructured param. The actual regex is
built inline below; the array slot wasn't doing anything.
@JohnMcLear JohnMcLear merged commit b805c17 into main May 9, 2026
5 checks passed
@JohnMcLear JohnMcLear deleted the fix/import-style-font-family branch May 9, 2026 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants