diff --git a/services/web/frontend/js/features/source-editor/extensions/visual/paste-html.ts b/services/web/frontend/js/features/source-editor/extensions/visual/paste-html.ts
index 8068063d24..0c167f8fa6 100644
--- a/services/web/frontend/js/features/source-editor/extensions/visual/paste-html.ts
+++ b/services/web/frontend/js/features/source-editor/extensions/visual/paste-html.ts
@@ -449,8 +449,7 @@ const selectors = [
createSelector({
selector: 'b',
match: element =>
- element.style.fontWeight !== 'normal' &&
- !(parseInt(element.style.fontWeight) < 700) &&
+ !element.style.fontWeight &&
!isHeading(element.parentElement) &&
hasContent(element),
start: () => '\\textbf{',
@@ -468,17 +467,13 @@ const selectors = [
}),
createSelector({
selector: 'strong',
- match: element =>
- element.style.fontWeight !== 'normal' &&
- !(parseInt(element.style.fontWeight) < 700) &&
- hasContent(element),
+ match: element => !element.style.fontWeight && hasContent(element),
start: () => '\\textbf{',
end: () => '}',
}),
createSelector({
selector: 'i',
- match: element =>
- element.style.fontStyle !== 'normal' && hasContent(element),
+ match: element => !element.style.fontStyle && hasContent(element),
start: () => '\\textit{',
end: () => '}',
}),
@@ -491,14 +486,13 @@ const selectors = [
}),
createSelector({
selector: 'em',
- match: element =>
- element.style.fontStyle !== 'normal' && hasContent(element),
+ match: element => !element.style.fontStyle && hasContent(element),
start: () => '\\textit{',
end: () => '}',
}),
createSelector({
selector: 'sup',
- match: element => hasContent(element),
+ match: element => !element.style.verticalAlign && hasContent(element),
start: () => '\\textsuperscript{',
end: () => '}',
}),
@@ -511,7 +505,7 @@ const selectors = [
}),
createSelector({
selector: 'sub',
- match: element => hasContent(element),
+ match: element => !element.style.verticalAlign && hasContent(element),
start: () => '\\textsubscript{',
end: () => '}',
}),
diff --git a/services/web/test/frontend/features/source-editor/components/codemirror-editor-visual-paste-html.spec.tsx b/services/web/test/frontend/features/source-editor/components/codemirror-editor-visual-paste-html.spec.tsx
index b8057d4882..7e9024a3f4 100644
--- a/services/web/test/frontend/features/source-editor/components/codemirror-editor-visual-paste-html.spec.tsx
+++ b/services/web/test/frontend/features/source-editor/components/codemirror-editor-visual-paste-html.spec.tsx
@@ -479,6 +479,25 @@ describe(' paste HTML in Visual mode', function () {
cy.get('.ol-cm-command-textit').should('have.length', 0)
})
+ it('handles pasted elements with duplicate CSS formatting', function () {
+ mountEditor()
+
+ const data = [
+ 'foo',
+ 'foo',
+ 'foo',
+ 'foo',
+ 'foo',
+ ].join(' ')
+
+ const clipboardData = new DataTransfer()
+ clipboardData.setData('text/html', data)
+ cy.get('@content').trigger('paste', { clipboardData })
+
+ cy.get('.ol-cm-command-textbf').should('have.length', 2)
+ cy.get('.ol-cm-command-textit').should('have.length', 2)
+ })
+
it('removes a non-breaking space when a text node contains no other content', function () {
mountEditor()