Avoid adding semantic style from an element which has explicit style (#14781)

GitOrigin-RevId: ae36022a9da36be0703c7e8e04e133975fadb893
This commit is contained in:
Alf Eaton 2023-09-14 09:17:00 +01:00 committed by Copybot
parent c28c7d5da2
commit 496b30e18e
2 changed files with 25 additions and 12 deletions

View file

@ -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: () => '}',
}),

View file

@ -479,6 +479,25 @@ describe('<CodeMirrorEditor/> 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 = [
'<strong style="font-weight:bold">foo</strong>',
'<b style="font-weight:bold">foo</b>',
'<em style="font-style:italic">foo</em>',
'<i style="font-style:italic">foo</i>',
'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()