MDL-83794 editor_tiny: Add SVG support

This commit is contained in:
Andrew Nicols
2025-01-30 07:23:57 +08:00
parent f67b2e8c6b
commit 7ca85dfd6e
6 changed files with 36 additions and 5 deletions
+30
View File
@@ -85,3 +85,33 @@ export const addMathMLSupport = (editor) => {
}));
});
};
/**
* Add SVG support to the editor.
*
* @param {TinyMCE} editor
*/
export const addSVGSupport = (editor) => {
editor.on('PreInit', () => {
editor.schema.addCustomElements({
// Add support for SVG by defining an SVG tag which extends DIV.
// Note: This is blind support and does not check the child content.
// Any invalid markup will be accepted.
svg: {
'extends': "div",
},
'tiny-svg-block': {
'extends': "div",
},
});
editor.parser.addNodeFilter('svg', (nodes) => nodes.forEach((node) => {
node.wrap(editor.editorManager.html.Node.create('tiny-svg-block', {
contenteditable: 'false',
}));
}));
editor.serializer.addNodeFilter('tiny-svg-block', (nodes) => nodes.forEach((node) => {
node.unwrap();
}));
});
};
+2 -1
View File
@@ -28,7 +28,7 @@ import {getTinyMCE, baseUrl} from './loader';
import * as Options from './options';
import {addToolbarButton, addToolbarButtons, addToolbarSection,
removeToolbarButton, removeSubmenuItem, updateEditorState} from './utils';
import {addMathMLSupport} from './content';
import {addMathMLSupport, addSVGSupport} from './content';
/**
* Storage for the TinyMCE instances on the page.
@@ -364,6 +364,7 @@ const getStandardConfig = (target, tinyMCE, options, plugins) => {
});
addMathMLSupport(editor);
addSVGSupport(editor);
target.addEventListener('form:editorUpdated', function() {
updateEditorState(editor, target);