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 dfd8201833..8068063d24 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
@@ -450,6 +450,7 @@ const selectors = [
selector: 'b',
match: element =>
element.style.fontWeight !== 'normal' &&
+ !(parseInt(element.style.fontWeight) < 700) &&
!isHeading(element.parentElement) &&
hasContent(element),
start: () => '\\textbf{',
@@ -458,14 +459,19 @@ const selectors = [
createSelector({
selector: '*',
match: element =>
- parseInt(element.style.fontWeight) >= 700 && hasContent(element),
+ (element.style.fontWeight === 'bold' ||
+ parseInt(element.style.fontWeight) >= 700) &&
+ hasContent(element),
start: () => '\\textbf{',
end: () => '}',
inside: true,
}),
createSelector({
selector: 'strong',
- match: element => hasContent(element),
+ match: element =>
+ element.style.fontWeight !== 'normal' &&
+ !(parseInt(element.style.fontWeight) < 700) &&
+ hasContent(element),
start: () => '\\textbf{',
end: () => '}',
}),
@@ -485,7 +491,8 @@ const selectors = [
}),
createSelector({
selector: 'em',
- match: element => hasContent(element),
+ match: element =>
+ element.style.fontStyle !== 'normal' && hasContent(element),
start: () => '\\textit{',
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 e345863b98..b8057d4882 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
@@ -424,6 +424,61 @@ describe(' paste HTML in Visual mode', function () {
cy.get('.ol-cm-command-textsubscript').should('have.length', 1)
})
+ it('handles pasted text with bold CSS formatting', function () {
+ mountEditor()
+
+ const data =
+ 'foo foo foo'
+
+ const clipboardData = new DataTransfer()
+ clipboardData.setData('text/html', data)
+ cy.get('@content').trigger('paste', { clipboardData })
+
+ cy.get('@content').should('have.text', 'foo foo foo')
+ cy.get('.ol-cm-command-textbf').should('have.length', 2)
+ })
+
+ it('handles pasted text with italic CSS formatting', function () {
+ mountEditor()
+
+ const data = 'foo foo'
+
+ const clipboardData = new DataTransfer()
+ clipboardData.setData('text/html', data)
+ cy.get('@content').trigger('paste', { clipboardData })
+
+ cy.get('@content').should('have.text', 'foo foo')
+ cy.get('.ol-cm-command-textit').should('have.length', 1)
+ })
+
+ it('handles pasted text with non-bold CSS', function () {
+ mountEditor()
+
+ const data =
+ 'foo foo foo'
+
+ const clipboardData = new DataTransfer()
+ clipboardData.setData('text/html', data)
+ cy.get('@content').trigger('paste', { clipboardData })
+
+ cy.get('@content').should('have.text', 'foo foo foo')
+ cy.get('.ol-cm-command-textbf').should('have.length', 0)
+ })
+
+ it('handles pasted text with non-italic CSS', function () {
+ mountEditor()
+
+ const data =
+ 'foo foo foo'
+
+ const clipboardData = new DataTransfer()
+ clipboardData.setData('text/html', data)
+ cy.get('@content').trigger('paste', { clipboardData })
+
+ cy.get('@content').should('have.text', 'foo foo foo')
+ cy.get('.ol-cm-command-textit').should('have.length', 0)
+ })
+
it('removes a non-breaking space when a text node contains no other content', function () {
mountEditor()