Skip to content

Commit cd882a6

Browse files
author
gjulivan
committed
fix: e2e and styling
1 parent eb9422e commit cd882a6

8 files changed

Lines changed: 57 additions & 41 deletions

File tree

6.55 KB
Loading

packages/pluggableWidgets/rich-text-web/src/components/toolbars/Toolbar.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,14 @@ $rte-shadow-color: #00000014 !default;
8989
.toolbar-dropdown-button {
9090
display: flex;
9191
gap: 4px;
92-
padding: 6px 6px 3px;
92+
padding: 6px 2px 2px 2px;
9393
min-width: 120px;
9494
justify-content: space-between;
9595
background: none;
9696
border: none;
97+
margin: 0 var(--spacing-smallest, 2px);
98+
border-radius: var(--border-radius-s, 4px);
99+
background-color: var(--gray-50, var(--gray-lighter, #f8f8f8));
97100

98101
.dropdown-label {
99102
flex: 1;

packages/pluggableWidgets/rich-text-web/src/components/toolbars/components/Dialog.scss

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,7 @@
106106
}
107107

108108
.image-dialog-entity {
109-
margin-bottom: 12px;
110-
padding: 12px;
111-
border: 1px solid var(--border-color-default, #ced0d3);
112-
border-radius: 4px;
113-
background: #fafafa;
109+
margin: 0 var(--spacing-medium, 16px);
114110
min-height: 100px;
115111
}
116112

packages/pluggableWidgets/rich-text-web/src/components/toolbars/helpers/__tests__/colorPickerHelpers.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,33 @@ describe("colorPickerHelpers.handleColorClear", () => {
108108

109109
expect(editor.getHTML()).not.toContain("<mark");
110110
});
111+
112+
it("renders the text highlight as a span with a background color", () => {
113+
editor = makeEditor();
114+
editor.commands.setContent("<p>hello</p>");
115+
editor.commands.selectAll();
116+
117+
colorPickerHelpers.handleColorChange(editor, "textHighlight", "#ffff00");
118+
119+
const html = editor.getHTML();
120+
expect(html).not.toContain("<mark");
121+
expect(html).toContain("<span");
122+
expect(html).toContain("background-color");
123+
});
124+
125+
it("preserves highlighted text pasted from Microsoft Word", () => {
126+
editor = makeEditor();
127+
// Word emits highlights as spans using the `background` shorthand (never a
128+
// <mark>). The CSSOM expands `background` into `backgroundColor`, so our span
129+
// parser picks it up. A keyword like `yellow` is validated by isSafeCssColor
130+
// via CSS.supports in real browsers; here we use an explicit rgb value so the
131+
// assertion is deterministic under jsdom (which lacks CSS.supports).
132+
editor.commands.setContent(
133+
'<p><span style="background:rgb(255, 255, 0);mso-highlight:yellow">highlighted</span></p>'
134+
);
135+
136+
const html = editor.getHTML();
137+
expect(html).not.toContain("<mark");
138+
expect(html).toContain("background-color");
139+
});
111140
});

packages/pluggableWidgets/rich-text-web/src/extensions/TextHighlightClass.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Extension } from "@tiptap/core";
1+
import { Extension, mergeAttributes } from "@tiptap/core";
22
import { Highlight } from "@tiptap/extension-highlight";
33
import { isSafeCssColor } from "../utils/helpers";
44

@@ -60,6 +60,7 @@ export const TextHighlightClass = Extension.create<TextHighlightClassOptions>({
6060
};
6161
} else {
6262
return {
63+
class: "has-text-highlight",
6364
style: `background-color: ${attributes.color}`
6465
};
6566
}
@@ -70,22 +71,29 @@ export const TextHighlightClass = Extension.create<TextHighlightClassOptions>({
7071
parseHTML() {
7172
return [
7273
{
73-
tag: "mark",
74+
tag: "span",
7475
getAttrs: element => {
7576
const htmlElement = element as HTMLElement;
76-
const hasStyles =
77-
htmlElement.hasAttribute("style") ||
78-
htmlElement.hasAttribute("data-text-highlight") ||
79-
htmlElement.style.backgroundColor;
77+
// Only treat a span as a highlight when it actually carries a
78+
// background (inline mode, incl. Word's `background` shorthand which
79+
// the CSSOM expands into `backgroundColor`) or our data attribute
80+
// (class mode). This avoids capturing color-only text-style spans.
81+
const hasHighlight =
82+
styleDataFormat === "class"
83+
? !!htmlElement.dataset.textHighlight
84+
: !!htmlElement.style.backgroundColor;
8085

81-
if (!hasStyles) {
86+
if (!hasHighlight) {
8287
return false;
8388
}
8489

8590
return {};
8691
}
8792
}
8893
];
94+
},
95+
renderHTML({ HTMLAttributes }) {
96+
return ["span", mergeAttributes(HTMLAttributes), 0];
8997
}
9098
}).configure({
9199
multicolor: this.options.multicolor

packages/pluggableWidgets/rich-text-web/src/ui/RichText.scss

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ $rte-brand-primary: #264ae5;
136136
}
137137
}
138138

139-
mark {
139+
.has-text-highlight {
140140
padding: 0.1em 0.2em;
141141
border-radius: 2px;
142142
}
@@ -315,27 +315,14 @@ $rte-brand-primary: #264ae5;
315315
}
316316

317317
code {
318-
background-color: var(--gray-900, #616161);
319-
color: var(--font-color-contrast, #fff);
320-
padding: 0.2em 0.4em;
318+
background: var(--gray-50, var(--gray-lighter, #f8f8f8));
319+
padding: 0.15rem 0.55rem;
321320
border-radius: 3px;
322-
font-size: 1.2rem;
323321
font-family: "Courier New", Courier, monospace;
324322
}
325323

326324
pre {
327-
background: var(--color-contrast, #000);
328-
color: var(--font-color-contrast, #fff);
329-
font-family: "JetBrainsMono", monospace;
330-
padding: 0.75rem;
331-
border-radius: 0.5rem;
332-
333-
code {
334-
color: inherit;
335-
padding: 0;
336-
background: none;
337-
font-size: 1.1rem;
338-
}
325+
padding: 0.15rem 0.55rem;
339326
}
340327

341328
blockquote {

packages/pluggableWidgets/rich-text-web/src/ui/RichTextFormatStyle.scss

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@
3333
margin: 0;
3434
}
3535

36-
mark {
37-
color: inherit;
38-
background-color: inherit;
39-
}
40-
4136
.has-text-color {
4237
color: attr(data-text-color type(<color>));
4338
}

pnpm-lock.yaml

Lines changed: 4 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)