MDL-83794 editor_tiny: Explicitly list MathML content
This commit is contained in:
+9
-1
@@ -1,3 +1,11 @@
|
||||
define("editor_tiny/content",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.addSVGSupport=_exports.addMathMLSupport=void 0;_exports.addMathMLSupport=editor=>{editor.on("PreInit",(()=>{editor.schema.addCustomElements({math:{extends:"div"},"tiny-math-span":{extends:"span"},"tiny-math-block":{extends:"div"}}),editor.parser.addNodeFilter("math",(nodes=>nodes.forEach((node=>{if(node.parent&&("tiny-math-block"===node.parent.name||"tiny-math-span"===node.parent.name))return;const displayMode=(node=>{const style=node.attr("style");return null!=style&&style.includes("display")&&style.match(/display:[^;]*inline/)?"tiny-math-span":"tiny-math-block"})(node);node.wrap(editor.editorManager.html.Node.create(displayMode,{contenteditable:"false"}))})))),editor.serializer.addNodeFilter("tiny-math-span, tiny-math-block",((nodes,name)=>nodes.forEach((node=>{const displayMode=name.replace("tiny-math-","");node.children().forEach((child=>{const currentStyle=child.attr("style");currentStyle?child.attr("style","".concat(currentStyle,";display: ").concat(displayMode)):child.attr("style","display: ".concat(displayMode))})),node.unwrap()}))))}))};_exports.addSVGSupport=editor=>{editor.on("PreInit",(()=>{editor.schema.addCustomElements({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()}))))}))}}));
|
||||
define("editor_tiny/content",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.addSVGSupport=_exports.addMathMLSupport=void 0;
|
||||
/**
|
||||
* Module to assist with creation and management of content.
|
||||
*
|
||||
* @module editor_tiny/content
|
||||
* @copyright Andrew Lyons <andrew@nicols.co.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
const mathmlContent=["math","maction","annotation","annotation-xml","menclose","merror","mfenced","mfrac","mi","mmultiscripts","mn","mo","mover","mpadded","mphantom","mprescripts","mroot","mrow","ms","semantics","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","math","mi","mn","mo","ms","mspace","mtext","menclose","merror","mfenced","mfrac","mpadded","mphantom","mroot","mrow","msqrt","mstyle","mmultiscripts","mover","mprescripts","msub","msubsup","msup","munder","munderover","mtable","mtd","mtr","maction","annotation","annotation-xml","semantics"];_exports.addMathMLSupport=editor=>{editor.on("PreInit",(()=>{editor.schema.addCustomElements(mathmlContent.join(",")),editor.schema.addCustomElements("~tiny-math-span,tiny-math-block"),editor.parser.addNodeFilter("math",(nodes=>nodes.forEach((node=>{if(node.parent&&("tiny-math-block"===node.parent.name||"tiny-math-span"===node.parent.name))return;const displayMode=(node=>{const style=node.attr("style");return null!=style&&style.includes("display")&&style.match(/display:[^;]*inline/)?"tiny-math-span":"tiny-math-block"})(node);node.wrap(editor.editorManager.html.Node.create(displayMode,{contenteditable:"false"}))})))),editor.serializer.addNodeFilter("tiny-math-span, tiny-math-block",((nodes,name)=>nodes.forEach((node=>{const displayMode=name.replace("tiny-math-","");node.children().forEach((child=>{const currentStyle=child.attr("style");currentStyle?child.attr("style","".concat(currentStyle,";display: ").concat(displayMode)):child.attr("style","display: ".concat(displayMode))})),node.unwrap()}))))}))};_exports.addSVGSupport=editor=>{editor.on("PreInit",(()=>{editor.schema.addCustomElements("svg,tiny-svg-block"),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()}))))}))}}));
|
||||
|
||||
//# sourceMappingURL=content.min.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -14,13 +14,81 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* TODO describe module content
|
||||
* Module to assist with creation and management of content.
|
||||
*
|
||||
* @module editor_tiny/content
|
||||
* @copyright 2025 Andrew Lyons <[email protected]>
|
||||
* @copyright Andrew Lyons <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
// MathML valid elements retrieved from https://developer.mozilla.org/en-US/docs/Web/MathML/Element.
|
||||
const mathmlContent = [
|
||||
'math',
|
||||
'maction',
|
||||
'annotation',
|
||||
'annotation-xml',
|
||||
'menclose',
|
||||
'merror',
|
||||
'mfenced',
|
||||
'mfrac',
|
||||
'mi',
|
||||
'mmultiscripts',
|
||||
'mn',
|
||||
'mo',
|
||||
'mover',
|
||||
'mpadded',
|
||||
'mphantom',
|
||||
'mprescripts',
|
||||
'mroot',
|
||||
'mrow',
|
||||
'ms',
|
||||
'semantics',
|
||||
'mspace',
|
||||
'msqrt',
|
||||
'mstyle',
|
||||
'msub',
|
||||
'msup',
|
||||
'msubsup',
|
||||
'mtable',
|
||||
'mtd',
|
||||
'mtext',
|
||||
'mtr',
|
||||
'munder',
|
||||
'munderover',
|
||||
'math',
|
||||
'mi',
|
||||
'mn',
|
||||
'mo',
|
||||
'ms',
|
||||
'mspace',
|
||||
'mtext',
|
||||
'menclose',
|
||||
'merror',
|
||||
'mfenced',
|
||||
'mfrac',
|
||||
'mpadded',
|
||||
'mphantom',
|
||||
'mroot',
|
||||
'mrow',
|
||||
'msqrt',
|
||||
'mstyle',
|
||||
'mmultiscripts',
|
||||
'mover',
|
||||
'mprescripts',
|
||||
'msub',
|
||||
'msubsup',
|
||||
'msup',
|
||||
'munder',
|
||||
'munderover',
|
||||
'mtable',
|
||||
'mtd',
|
||||
'mtr',
|
||||
'maction',
|
||||
'annotation',
|
||||
'annotation-xml',
|
||||
'semantics',
|
||||
];
|
||||
|
||||
/**
|
||||
* Add MathML support to the editor.
|
||||
*
|
||||
@@ -39,21 +107,8 @@ export const addMathMLSupport = (editor) => {
|
||||
|
||||
|
||||
editor.on('PreInit', () => {
|
||||
editor.schema.addCustomElements({
|
||||
// Add support for MathML by defining some tiny-math blocks which extends SPAN/DIV.
|
||||
// Note: This is blind support and does not check the child content.
|
||||
// Any invalid markup will be accepted.
|
||||
// Note: We use the same names as the Tiny Premium Math plugin to avoid conflicts if both are enabled.
|
||||
math: {
|
||||
'extends': 'div',
|
||||
},
|
||||
'tiny-math-span': {
|
||||
'extends': "span",
|
||||
},
|
||||
'tiny-math-block': {
|
||||
'extends': "div",
|
||||
},
|
||||
});
|
||||
editor.schema.addCustomElements(mathmlContent.join(','));
|
||||
editor.schema.addCustomElements('~tiny-math-span,tiny-math-block');
|
||||
|
||||
// Add a Parser filter to wrap math nodes in a tiny-math-[block|span] element.
|
||||
editor.parser.addNodeFilter('math', (nodes) => nodes.forEach((node) => {
|
||||
@@ -93,17 +148,7 @@ export const addMathMLSupport = (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.schema.addCustomElements('svg,tiny-svg-block');
|
||||
|
||||
editor.parser.addNodeFilter('svg', (nodes) => nodes.forEach((node) => {
|
||||
node.wrap(editor.editorManager.html.Node.create('tiny-svg-block', {
|
||||
|
||||
Reference in New Issue
Block a user