@wiris/mathtype-ckeditor5 8.10.0 → 8.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index-editor.css +626 -502
- package/dist/browser/index.js +136 -47
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.umd.js +138 -49
- package/dist/browser/index.umd.js.map +1 -1
- package/dist/index.js +98 -33
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/index.js +1 -1
- package/src/integration.js +3 -0
- package/src/plugin.js +110 -31
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('ckeditor5')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['ckeditor5'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global["@wiris/mathtype-ckeditor5"] = factory(global.
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global["@wiris/mathtype-ckeditor5"] = factory(global.CKEDITOR));
|
|
5
5
|
})(this, (function (ckeditor5) { 'use strict';
|
|
6
6
|
|
|
7
7
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
@@ -559,6 +559,7 @@
|
|
|
559
559
|
'accumulate',
|
|
560
560
|
'additive',
|
|
561
561
|
'alignment-baseline',
|
|
562
|
+
'amplitude',
|
|
562
563
|
'ascent',
|
|
563
564
|
'attributename',
|
|
564
565
|
'attributetype',
|
|
@@ -591,6 +592,7 @@
|
|
|
591
592
|
'edgemode',
|
|
592
593
|
'elevation',
|
|
593
594
|
'end',
|
|
595
|
+
'exponent',
|
|
594
596
|
'fill',
|
|
595
597
|
'fill-opacity',
|
|
596
598
|
'fill-rule',
|
|
@@ -619,6 +621,7 @@
|
|
|
619
621
|
'image-rendering',
|
|
620
622
|
'in',
|
|
621
623
|
'in2',
|
|
624
|
+
'intercept',
|
|
622
625
|
'k',
|
|
623
626
|
'k1',
|
|
624
627
|
'k2',
|
|
@@ -683,6 +686,7 @@
|
|
|
683
686
|
'scale',
|
|
684
687
|
'seed',
|
|
685
688
|
'shape-rendering',
|
|
689
|
+
'slope',
|
|
686
690
|
'specularconstant',
|
|
687
691
|
'specularexponent',
|
|
688
692
|
'spreadmethod',
|
|
@@ -703,6 +707,7 @@
|
|
|
703
707
|
'surfacescale',
|
|
704
708
|
'systemlanguage',
|
|
705
709
|
'tabindex',
|
|
710
|
+
'tablevalues',
|
|
706
711
|
'targetx',
|
|
707
712
|
'targety',
|
|
708
713
|
'transform',
|
|
@@ -889,7 +894,7 @@
|
|
|
889
894
|
/**
|
|
890
895
|
* Version label, exposed for easier checks
|
|
891
896
|
* if DOMPurify is up to date or not
|
|
892
|
-
*/ DOMPurify.version = '3.1.
|
|
897
|
+
*/ DOMPurify.version = '3.1.7';
|
|
893
898
|
/**
|
|
894
899
|
* Array of elements that DOMPurify removed during sanitation.
|
|
895
900
|
* Empty if nothing was removed.
|
|
@@ -906,6 +911,7 @@
|
|
|
906
911
|
const { DocumentFragment, HTMLTemplateElement, Node, Element, NodeFilter, NamedNodeMap = window1.NamedNodeMap || window1.MozNamedAttrMap, HTMLFormElement, DOMParser, trustedTypes } = window1;
|
|
907
912
|
const ElementPrototype = Element.prototype;
|
|
908
913
|
const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
|
|
914
|
+
const remove = lookupGetter(ElementPrototype, 'remove');
|
|
909
915
|
const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
|
|
910
916
|
const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
|
|
911
917
|
const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
|
|
@@ -1261,7 +1267,6 @@
|
|
|
1261
1267
|
'mtext'
|
|
1262
1268
|
]);
|
|
1263
1269
|
const HTML_INTEGRATION_POINTS = addToSet({}, [
|
|
1264
|
-
'foreignobject',
|
|
1265
1270
|
'annotation-xml'
|
|
1266
1271
|
]);
|
|
1267
1272
|
// Certain elements are allowed in both SVG and HTML
|
|
@@ -1373,9 +1378,9 @@
|
|
|
1373
1378
|
});
|
|
1374
1379
|
try {
|
|
1375
1380
|
// eslint-disable-next-line unicorn/prefer-dom-node-remove
|
|
1376
|
-
node.
|
|
1381
|
+
getParentNode(node).removeChild(node);
|
|
1377
1382
|
} catch (_) {
|
|
1378
|
-
|
|
1383
|
+
remove(node);
|
|
1379
1384
|
}
|
|
1380
1385
|
};
|
|
1381
1386
|
/**
|
|
@@ -1518,7 +1523,7 @@
|
|
|
1518
1523
|
_forceRemove(currentNode);
|
|
1519
1524
|
return true;
|
|
1520
1525
|
}
|
|
1521
|
-
/* Remove any
|
|
1526
|
+
/* Remove any occurrence of processing instructions */ if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
|
|
1522
1527
|
_forceRemove(currentNode);
|
|
1523
1528
|
return true;
|
|
1524
1529
|
}
|
|
@@ -1667,10 +1672,6 @@
|
|
|
1667
1672
|
_removeAttribute(name, currentNode);
|
|
1668
1673
|
continue;
|
|
1669
1674
|
}
|
|
1670
|
-
/* Work around a security issue with comments inside attributes */ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value)) {
|
|
1671
|
-
_removeAttribute(name, currentNode);
|
|
1672
|
-
continue;
|
|
1673
|
-
}
|
|
1674
1675
|
/* Sanitize attribute content to be template-safe */ if (SAFE_FOR_TEMPLATES) {
|
|
1675
1676
|
arrayForEach([
|
|
1676
1677
|
MUSTACHE_EXPR,
|
|
@@ -1692,6 +1693,10 @@
|
|
|
1692
1693
|
// Prefix the value and later re-create the attribute with the sanitized value
|
|
1693
1694
|
value = SANITIZE_NAMED_PROPS_PREFIX + value;
|
|
1694
1695
|
}
|
|
1696
|
+
/* Work around a security issue with comments inside attributes */ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value)) {
|
|
1697
|
+
_removeAttribute(name, currentNode);
|
|
1698
|
+
continue;
|
|
1699
|
+
}
|
|
1695
1700
|
/* Handle attributes that require Trusted Types */ if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
|
|
1696
1701
|
if (namespaceURI) ;
|
|
1697
1702
|
else {
|
|
@@ -2267,6 +2272,19 @@
|
|
|
2267
2272
|
return mathml.replace(semanticsStartingTagRegex, "").replace(semanticsEndingTagRegex, "");
|
|
2268
2273
|
}
|
|
2269
2274
|
/**
|
|
2275
|
+
* Removes semantics tag to element that contains mathml.
|
|
2276
|
+
* When using Hand to create formulas, it adds the mrow tag due to the semantics one, this one is also removed.
|
|
2277
|
+
* @param {string} element - Inner HTML text string.
|
|
2278
|
+
* @returns {string} - 'mathml' without semantics tag.
|
|
2279
|
+
*/ static removeSafeXMLSemantics(element) {
|
|
2280
|
+
// If `mrow` is found right before the `semantics` starting tag, it's removed as well
|
|
2281
|
+
const semanticsSafeStartingTagRegex = /«semantics»\s*?(«mrow»)?/gm;
|
|
2282
|
+
// If `mrow` is found right after the `annotation` ending tag, it's removed as well
|
|
2283
|
+
// alongside `semantics` closing tag and the whole `annotation` tag and its contents.
|
|
2284
|
+
const semanticsSafeEndingTagRegex = /(«\/mrow»)?\s*«annotation[\W\w]*?«\/semantics»/gm;
|
|
2285
|
+
return element.replace(semanticsSafeStartingTagRegex, "").replace(semanticsSafeEndingTagRegex, "");
|
|
2286
|
+
}
|
|
2287
|
+
/**
|
|
2270
2288
|
* Transforms all xml mathml occurrences that contain semantics to the same
|
|
2271
2289
|
* xml mathml occurrences without semantics.
|
|
2272
2290
|
* @param {string} text - string that can contain xml mathml occurrences.
|
|
@@ -3589,6 +3607,9 @@
|
|
|
3589
3607
|
var nl = {
|
|
3590
3608
|
latex: "LaTeX",
|
|
3591
3609
|
cancel: "Annuleren",
|
|
3610
|
+
accept: "Invoegen",
|
|
3611
|
+
manual: "Handmatig",
|
|
3612
|
+
insert_math: "Een wiskundige vergelijking invoegen - MathType",
|
|
3592
3613
|
insert_chem: "Een scheikundige formule invoegen - ChemType",
|
|
3593
3614
|
minimize: "Minimaliseer",
|
|
3594
3615
|
maximize: "Maximaliseer",
|
|
@@ -4352,7 +4373,8 @@
|
|
|
4352
4373
|
"annotation",
|
|
4353
4374
|
"mstack",
|
|
4354
4375
|
"msline",
|
|
4355
|
-
"msrow"
|
|
4376
|
+
"msrow",
|
|
4377
|
+
"none"
|
|
4356
4378
|
],
|
|
4357
4379
|
ADD_ATTR: [
|
|
4358
4380
|
"linebreak",
|
|
@@ -5517,12 +5539,14 @@
|
|
|
5517
5539
|
* @param {string} code - HTML code to be parsed
|
|
5518
5540
|
* @returns {string} HTML code parsed.
|
|
5519
5541
|
*/ static endParseSaveMode(code) {
|
|
5520
|
-
|
|
5521
|
-
|
|
5542
|
+
const savemode = Configuration.get("saveMode");
|
|
5543
|
+
const base64savemode = Configuration.get("base64savemode");
|
|
5544
|
+
if (savemode) {
|
|
5545
|
+
if (savemode === "safeXml") {
|
|
5522
5546
|
code = Parser.codeImgTransform(code, "img2mathml");
|
|
5523
|
-
} else if (
|
|
5547
|
+
} else if (savemode === "xml") {
|
|
5524
5548
|
code = Parser.codeImgTransform(code, "img2mathml");
|
|
5525
|
-
} else if (
|
|
5549
|
+
} else if (savemode === "base64" && base64savemode === "image") {
|
|
5526
5550
|
code = Parser.codeImgTransform(code, "img264");
|
|
5527
5551
|
}
|
|
5528
5552
|
}
|
|
@@ -6692,7 +6716,7 @@
|
|
|
6692
6716
|
async function __wbg_init(input) {
|
|
6693
6717
|
if (wasm !== undefined) return wasm;
|
|
6694
6718
|
if (typeof input === "undefined") {
|
|
6695
|
-
input = new URL("telemeter_wasm_bg.wasm", (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.umd.js', document.baseURI).href)));
|
|
6719
|
+
input = new URL("telemeter_wasm_bg.wasm", (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.umd.js', document.baseURI).href)));
|
|
6696
6720
|
}
|
|
6697
6721
|
const imports = __wbg_get_imports();
|
|
6698
6722
|
if (typeof input === "string" || typeof Request === "function" && input instanceof Request || typeof URL === "function" && input instanceof URL) {
|
|
@@ -10533,6 +10557,8 @@
|
|
|
10533
10557
|
openNewFormulaEditor() {
|
|
10534
10558
|
// Store the editor selection as it will be lost upon opening the modal
|
|
10535
10559
|
this.core.editionProperties.selection = this.editorObject.editing.view.document.selection;
|
|
10560
|
+
// Focus on the selected editor when multiple editor instances are present
|
|
10561
|
+
WirisPlugin.currentInstance = this;
|
|
10536
10562
|
return super.openNewFormulaEditor();
|
|
10537
10563
|
}
|
|
10538
10564
|
/**
|
|
@@ -10767,7 +10793,7 @@
|
|
|
10767
10793
|
var chemIcon = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!-- Generator: Adobe Illustrator 22.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->\n<svg version=\"1.1\" id=\"Layer_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\"\n\t viewBox=\"0 0 40.3 49.5\" style=\"enable-background:new 0 0 40.3 49.5;\" xml:space=\"preserve\">\n<style type=\"text/css\">\n\t.st0{fill:#A4CF61;}\n</style>\n<path class=\"st0\" d=\"M39.2,12.1c0-1.9-1.1-3.6-2.7-4.4L24.5,0.9l0,0c-0.7-0.4-1.5-0.6-2.4-0.6c-0.9,0-1.7,0.2-2.4,0.6l0,0L2.3,10.8\n\tl0,0C0.9,11.7,0,13.2,0,14.9h0v19.6h0c0,1.7,0.9,3.3,2.3,4.1l0,0l17.4,9.9l0,0c0.7,0.4,1.5,0.6,2.4,0.6c0.9,0,1.7-0.2,2.4-0.6l0,0\n\tl12.2-6.9h0c1.5-0.8,2.6-2.5,2.6-4.3c0-2.7-2.2-4.9-4.9-4.9c-0.9,0-1.8,0.3-2.5,0.7l0,0l-9.7,5.6l-12.3-7V17.8l12.3-7l9.9,5.7l0,0\n\tc0.7,0.4,1.5,0.6,2.4,0.6C37,17,39.2,14.8,39.2,12.1\"/>\n</svg>\n";
|
|
10768
10794
|
|
|
10769
10795
|
var name = "@wiris/mathtype-ckeditor5";
|
|
10770
|
-
var version = "8.
|
|
10796
|
+
var version = "8.11.1";
|
|
10771
10797
|
var description = "MathType Web for CKEditor5 editor";
|
|
10772
10798
|
var keywords = [
|
|
10773
10799
|
"chem",
|
|
@@ -10802,8 +10828,8 @@
|
|
|
10802
10828
|
var type = "module";
|
|
10803
10829
|
var exports$1 = {
|
|
10804
10830
|
".": "./src/plugin.js",
|
|
10805
|
-
"./dist/*.css": "./dist/*.css",
|
|
10806
10831
|
"./dist/*": "./dist/*",
|
|
10832
|
+
"./browser/*": null,
|
|
10807
10833
|
"./src/*": "./src/*",
|
|
10808
10834
|
"./theme/*": "./theme/*",
|
|
10809
10835
|
"./package.json": "./package.json"
|
|
@@ -10814,14 +10840,14 @@
|
|
|
10814
10840
|
prepare: "npm run build:dist"
|
|
10815
10841
|
};
|
|
10816
10842
|
var dependencies = {
|
|
10817
|
-
"@wiris/mathtype-html-integration-devkit": "1.17.
|
|
10843
|
+
"@wiris/mathtype-html-integration-devkit": "1.17.5"
|
|
10818
10844
|
};
|
|
10819
10845
|
var devDependencies = {
|
|
10820
|
-
"@ckeditor/ckeditor5-dev-build-tools": "^
|
|
10821
|
-
ckeditor5: ">=
|
|
10846
|
+
"@ckeditor/ckeditor5-dev-build-tools": "^42.1.0",
|
|
10847
|
+
ckeditor5: ">=43.0.0"
|
|
10822
10848
|
};
|
|
10823
10849
|
var peerDependencies = {
|
|
10824
|
-
ckeditor5: ">=
|
|
10850
|
+
ckeditor5: ">=43.0.0"
|
|
10825
10851
|
};
|
|
10826
10852
|
var packageInfo = {
|
|
10827
10853
|
name: name,
|
|
@@ -10983,7 +11009,8 @@
|
|
|
10983
11009
|
schema.register("mathml", {
|
|
10984
11010
|
inheritAllFrom: "$inlineObject",
|
|
10985
11011
|
allowAttributes: [
|
|
10986
|
-
"formula"
|
|
11012
|
+
"formula",
|
|
11013
|
+
"htmlContent"
|
|
10987
11014
|
]
|
|
10988
11015
|
});
|
|
10989
11016
|
}
|
|
@@ -11067,6 +11094,50 @@
|
|
|
11067
11094
|
data.modelCursor = data.modelRange.end;
|
|
11068
11095
|
}
|
|
11069
11096
|
});
|
|
11097
|
+
// Data view -> Model
|
|
11098
|
+
editor.data.upcastDispatcher.on("element:img", (evt, data, conversionApi)=>{
|
|
11099
|
+
const { consumable, writer } = conversionApi;
|
|
11100
|
+
const { viewItem } = data;
|
|
11101
|
+
// Only upcast when is wiris formula
|
|
11102
|
+
if (viewItem.getClassNames().next().value !== "Wirisformula") {
|
|
11103
|
+
return;
|
|
11104
|
+
}
|
|
11105
|
+
const mathAttributes = [
|
|
11106
|
+
...viewItem.getAttributes()
|
|
11107
|
+
].map(([key, value])=>` ${key}="${value}"`).join("");
|
|
11108
|
+
let htmlContent = Util.htmlSanitize(`<img${mathAttributes}>`);
|
|
11109
|
+
const modelNode = writer.createElement("mathml", {
|
|
11110
|
+
htmlContent
|
|
11111
|
+
});
|
|
11112
|
+
// Find allowed parent for element that we are going to insert.
|
|
11113
|
+
// If current parent does not allow to insert element but one of the ancestors does
|
|
11114
|
+
// then split nodes to allowed parent.
|
|
11115
|
+
const splitResult = conversionApi.splitToAllowedParent(modelNode, data.modelCursor);
|
|
11116
|
+
// When there is no split result it means that we can't insert element to model tree, so let's skip it.
|
|
11117
|
+
if (!splitResult) {
|
|
11118
|
+
return;
|
|
11119
|
+
}
|
|
11120
|
+
// Insert element on allowed position.
|
|
11121
|
+
conversionApi.writer.insert(modelNode, splitResult.position);
|
|
11122
|
+
// Consume appropriate value from consumable values list.
|
|
11123
|
+
consumable.consume(viewItem, {
|
|
11124
|
+
name: true
|
|
11125
|
+
});
|
|
11126
|
+
const parts = conversionApi.getSplitParts(modelNode);
|
|
11127
|
+
// Set conversion result range.
|
|
11128
|
+
data.modelRange = writer.createRange(conversionApi.writer.createPositionBefore(modelNode), conversionApi.writer.createPositionAfter(parts[parts.length - 1]));
|
|
11129
|
+
// Now we need to check where the `modelCursor` should be.
|
|
11130
|
+
if (splitResult.cursorParent) {
|
|
11131
|
+
// If we split parent to insert our element then we want to continue conversion in the new part of the split parent.
|
|
11132
|
+
//
|
|
11133
|
+
// before: <allowed><notAllowed>foo[]</notAllowed></allowed>
|
|
11134
|
+
// after: <allowed><notAllowed>foo</notAllowed><converted></converted><notAllowed>[]</notAllowed></allowed>
|
|
11135
|
+
data.modelCursor = conversionApi.writer.createPositionAt(splitResult.cursorParent, 0);
|
|
11136
|
+
} else {
|
|
11137
|
+
// Otherwise just continue after inserted element.
|
|
11138
|
+
data.modelCursor = data.modelRange.end;
|
|
11139
|
+
}
|
|
11140
|
+
});
|
|
11070
11141
|
/**
|
|
11071
11142
|
* Whether the given view <math> element has a LaTeX annotation element.
|
|
11072
11143
|
* @param {*} math
|
|
@@ -11095,12 +11166,25 @@
|
|
|
11095
11166
|
}
|
|
11096
11167
|
function createViewImage(modelItem, { writer: viewWriter }) {
|
|
11097
11168
|
const htmlDataProcessor = new ckeditor5.HtmlDataProcessor(viewWriter.document);
|
|
11098
|
-
const
|
|
11099
|
-
const
|
|
11100
|
-
|
|
11169
|
+
const formula = modelItem.getAttribute("formula");
|
|
11170
|
+
const htmlContent = modelItem.getAttribute("htmlContent");
|
|
11171
|
+
if (!formula && !htmlContent) {
|
|
11172
|
+
return null;
|
|
11173
|
+
}
|
|
11174
|
+
let imgElement = null;
|
|
11175
|
+
if (htmlContent) {
|
|
11176
|
+
imgElement = htmlDataProcessor.toView(htmlContent).getChild(0);
|
|
11177
|
+
} else if (formula) {
|
|
11178
|
+
const mathString = formula.replaceAll('ref="<"', 'ref="<"');
|
|
11179
|
+
const imgHtml = Parser.initParse(mathString, integration.getLanguage());
|
|
11180
|
+
imgElement = htmlDataProcessor.toView(imgHtml).getChild(0);
|
|
11181
|
+
// Add HTML element (<img>) to model
|
|
11182
|
+
viewWriter.setAttribute("htmlContent", imgHtml, modelItem);
|
|
11183
|
+
}
|
|
11101
11184
|
/* Although we use the HtmlDataProcessor to obtain the attributes,
|
|
11102
|
-
|
|
11103
|
-
|
|
11185
|
+
* we must create a new EmptyElement which is independent of the
|
|
11186
|
+
* DataProcessor being used by this editor instance
|
|
11187
|
+
*/ if (imgElement) {
|
|
11104
11188
|
return viewWriter.createEmptyElement("img", imgElement.getAttributes(), {
|
|
11105
11189
|
renderUnsafeAttributes: [
|
|
11106
11190
|
"src"
|
|
@@ -11141,7 +11225,8 @@
|
|
|
11141
11225
|
}
|
|
11142
11226
|
function createDataString(modelItem, { writer: viewWriter }) {
|
|
11143
11227
|
const htmlDataProcessor = new ckeditor5.HtmlDataProcessor(viewWriter.document);
|
|
11144
|
-
|
|
11228
|
+
// Load img element
|
|
11229
|
+
let mathString = modelItem.getAttribute("htmlContent");
|
|
11145
11230
|
const sourceMathElement = htmlDataProcessor.toView(mathString).getChild(0);
|
|
11146
11231
|
return clone(viewWriter, sourceMathElement);
|
|
11147
11232
|
}
|
|
@@ -11153,36 +11238,40 @@
|
|
|
11153
11238
|
* Hack to transform $$latex$$ into <math> in editor.getData()'s output.
|
|
11154
11239
|
*/ editor.data.on("get", (e)=>{
|
|
11155
11240
|
let output = e.return;
|
|
11156
|
-
|
|
11157
|
-
//
|
|
11158
|
-
|
|
11241
|
+
const parsedResult = Parser.endParse(output);
|
|
11242
|
+
// Cleans all the semantics tag for safexml
|
|
11243
|
+
// including the handwritten data points
|
|
11244
|
+
e.return = MathML.removeSafeXMLSemantics(parsedResult);
|
|
11159
11245
|
}, {
|
|
11160
11246
|
priority: "low"
|
|
11161
11247
|
});
|
|
11162
11248
|
/**
|
|
11163
|
-
* Hack to transform <math> with LaTeX into $$LaTeX$$ in editor.setData().
|
|
11249
|
+
* Hack to transform <math> with LaTeX into $$LaTeX$$ and formula images in editor.setData().
|
|
11164
11250
|
*/ editor.data.on("set", (e, args)=>{
|
|
11165
11251
|
// Retrieve the data to be set on the CKEditor.
|
|
11166
11252
|
let modifiedData = args[0];
|
|
11167
11253
|
// Regex to find all mathml formulas.
|
|
11168
|
-
const regexp =
|
|
11169
|
-
|
|
11170
|
-
|
|
11171
|
-
//
|
|
11172
|
-
|
|
11173
|
-
|
|
11174
|
-
|
|
11175
|
-
|
|
11176
|
-
] : [
|
|
11177
|
-
...modifiedData.matchAll(regexp)
|
|
11178
|
-
];
|
|
11179
|
-
// Loop to find LaTeX formulas and replace the MathML for the LaTeX notation.
|
|
11254
|
+
const regexp = /(<img\b[^>]*>)|(<math(.*?)<\/math>)/gm;
|
|
11255
|
+
const formulas = [];
|
|
11256
|
+
let formula;
|
|
11257
|
+
// Both data.set from the source plugin and console command are taken into account as the data received is MathML or an image containing the MathML.
|
|
11258
|
+
while((formula = regexp.exec(modifiedData)) !== null){
|
|
11259
|
+
formulas.push(formula[0]);
|
|
11260
|
+
}
|
|
11261
|
+
// Loop to find LaTeX and formula images and replace the MathML for the both.
|
|
11180
11262
|
formulas.forEach((formula)=>{
|
|
11181
|
-
|
|
11182
|
-
if (mathml.includes('encoding="LaTeX"')) {
|
|
11263
|
+
if (formula.includes('encoding="LaTeX"')) {
|
|
11183
11264
|
// LaTeX found.
|
|
11184
|
-
let latex = "$$$" + Latex.getLatexFromMathML(
|
|
11185
|
-
modifiedData = modifiedData.replace(
|
|
11265
|
+
let latex = "$$$" + Latex.getLatexFromMathML(formula) + "$$$"; // We add $$$ instead of $$ because the replace function ignores one $.
|
|
11266
|
+
modifiedData = modifiedData.replace(formula, latex);
|
|
11267
|
+
} else if (formula.includes("<img")) {
|
|
11268
|
+
// If we found a formula image, we should find MathML data, and then substitute the entire image.
|
|
11269
|
+
const regexp = /«math\b[^»]*»(.*?)«\/math»/g;
|
|
11270
|
+
const safexml = formula.match(regexp);
|
|
11271
|
+
if (safexml !== null) {
|
|
11272
|
+
let decodeXML = MathML.safeXmlDecode(safexml[0]);
|
|
11273
|
+
modifiedData = modifiedData.replace(formula, decodeXML);
|
|
11274
|
+
}
|
|
11186
11275
|
}
|
|
11187
11276
|
});
|
|
11188
11277
|
args[0] = modifiedData;
|