mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 20:34:02 +03:00
Koenig - Standardise <b> and <i> elements when pasting
refs https://github.com/TryGhost/Ghost/issues/9623 - use our paste handler to perform a replacement on any pasted HTML - `<b>` -> `<strong>` - `<i>` -> `<em>`
This commit is contained in:
parent
823f6afa80
commit
b9c81ac219
@ -661,6 +661,40 @@ export default Component.extend({
|
|||||||
|
|
||||||
editor.triggerEvent(editor.element, 'paste', pasteEvent);
|
editor.triggerEvent(editor.element, 'paste', pasteEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we need to standardise HTML here because parserPlugins do not get
|
||||||
|
// passed inline markup such as `<b>` or `<i>`
|
||||||
|
if (html) {
|
||||||
|
// prevent mobiledoc's default paste event handler firing
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopImmediatePropagation();
|
||||||
|
|
||||||
|
let normalizedHtml = html
|
||||||
|
.replace(/<b(\s|>)/gi, '<strong$1')
|
||||||
|
.replace(/<\/b>/gi, '</strong>')
|
||||||
|
.replace(/<i(\s|>)/gi, '<em$1')
|
||||||
|
.replace(/<\/i>/gi, '</em>');
|
||||||
|
|
||||||
|
// we can't modify the paste event itself so we trigger a mock
|
||||||
|
// paste event with our own data
|
||||||
|
let pasteEvent = {
|
||||||
|
type: 'paste',
|
||||||
|
preventDefault() {},
|
||||||
|
target: editor.element,
|
||||||
|
clipboardData: {
|
||||||
|
getData(type) {
|
||||||
|
if (type === 'text/plain') {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
if (type === 'text/html') {
|
||||||
|
return normalizedHtml;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
editor.triggerEvent(editor.element, 'paste', pasteEvent);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/* Ember event handlers ------------------------------------------------- */
|
/* Ember event handlers ------------------------------------------------- */
|
||||||
|
Loading…
Reference in New Issue
Block a user