fix: read font-family from inline style on HTML import#143
Merged
Conversation
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.
ⓘ 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. |
CodeQL flagged the unused destructured param. The actual regex is built inline below; the array slot wasn't doing anything.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ep_font_family stores the chosen font as a custom tag (
<fontarial>...</fontarial>) on the pad side.getLineHTMLForExportrewrites 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
collectContentPreto also scancontext.stylforfont-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').monospacemaps tofontmonospace; 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. CoversArial,'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).