Skip to content

Commit 11c24d3

Browse files
committed
test(paste): cover fromSpans guard paths and document headingSizeMap thresholds
1 parent 0ec3a54 commit 11c24d3

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

packages/super-editor/src/core/inputRules/google-docs-paste/google-docs-paste.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { createSingleItemList } from '../html/html-helpers.js';
55
import { getLvlTextForGoogleList, googleNumDefMap } from '../../helpers/pasteListHelpers.js';
66
import { wrapTextsInRuns } from '../docx-paste/docx-paste.js';
77

8-
// Ordered largest → smallest; first match wins.
8+
// Match Google Docs default heading sizes (H1=20pt, H2=18pt, H3=14pt, H4=12pt, H5=11pt).
9+
// Descending order so oversized fonts (e.g. 24pt) still resolve to closest heading.
910
const headingSizeMap = [
1011
{ minPt: 20, tag: 'h1' },
1112
{ minPt: 16, tag: 'h2' },

packages/super-editor/src/core/inputRules/google-docs-paste/google-docs-paste.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,22 @@ describe('handleGoogleDocsHtml', () => {
187187
expect(dom.querySelector('h1')?.textContent?.trim()).toBe('Bold p, size on span');
188188
});
189189

190+
it('does not convert when one span is missing a font-size', () => {
191+
const html = `
192+
<p><span style="font-size:20pt;font-weight:700">A</span><span style="font-weight:700">B</span></p>
193+
`;
194+
const dom = parseHeadings(html);
195+
expect(dom.querySelector('h1,h2,h3,h4,h5')).toBeNull();
196+
});
197+
198+
it('does not convert when spans have inconsistent font sizes', () => {
199+
const html = `
200+
<p><span style="font-size:20pt;font-weight:700">A</span><span style="font-size:14pt;font-weight:700">B</span></p>
201+
`;
202+
const dom = parseHeadings(html);
203+
expect(dom.querySelector('h1,h2,h3,h4,h5')).toBeNull();
204+
});
205+
190206
it('converts when font-size is on <p> but font-weight is only on the child <span>', () => {
191207
const html = `
192208
<p style="font-size:20pt"><span style="font-weight:700">Split style heading</span></p>

0 commit comments

Comments
 (0)