@wiris/mathtype-ckeditor5 8.11.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.js +124 -39
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.umd.js +125 -40
- package/dist/browser/index.umd.js.map +1 -1
- package/dist/index.js +92 -29
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.js +1 -1
- package/src/plugin.js +110 -31
package/dist/browser/index.js
CHANGED
|
@@ -557,6 +557,7 @@ var purify = {exports: {}};
|
|
|
557
557
|
'accumulate',
|
|
558
558
|
'additive',
|
|
559
559
|
'alignment-baseline',
|
|
560
|
+
'amplitude',
|
|
560
561
|
'ascent',
|
|
561
562
|
'attributename',
|
|
562
563
|
'attributetype',
|
|
@@ -589,6 +590,7 @@ var purify = {exports: {}};
|
|
|
589
590
|
'edgemode',
|
|
590
591
|
'elevation',
|
|
591
592
|
'end',
|
|
593
|
+
'exponent',
|
|
592
594
|
'fill',
|
|
593
595
|
'fill-opacity',
|
|
594
596
|
'fill-rule',
|
|
@@ -617,6 +619,7 @@ var purify = {exports: {}};
|
|
|
617
619
|
'image-rendering',
|
|
618
620
|
'in',
|
|
619
621
|
'in2',
|
|
622
|
+
'intercept',
|
|
620
623
|
'k',
|
|
621
624
|
'k1',
|
|
622
625
|
'k2',
|
|
@@ -681,6 +684,7 @@ var purify = {exports: {}};
|
|
|
681
684
|
'scale',
|
|
682
685
|
'seed',
|
|
683
686
|
'shape-rendering',
|
|
687
|
+
'slope',
|
|
684
688
|
'specularconstant',
|
|
685
689
|
'specularexponent',
|
|
686
690
|
'spreadmethod',
|
|
@@ -701,6 +705,7 @@ var purify = {exports: {}};
|
|
|
701
705
|
'surfacescale',
|
|
702
706
|
'systemlanguage',
|
|
703
707
|
'tabindex',
|
|
708
|
+
'tablevalues',
|
|
704
709
|
'targetx',
|
|
705
710
|
'targety',
|
|
706
711
|
'transform',
|
|
@@ -887,7 +892,7 @@ var purify = {exports: {}};
|
|
|
887
892
|
/**
|
|
888
893
|
* Version label, exposed for easier checks
|
|
889
894
|
* if DOMPurify is up to date or not
|
|
890
|
-
*/ DOMPurify.version = '3.1.
|
|
895
|
+
*/ DOMPurify.version = '3.1.7';
|
|
891
896
|
/**
|
|
892
897
|
* Array of elements that DOMPurify removed during sanitation.
|
|
893
898
|
* Empty if nothing was removed.
|
|
@@ -1260,7 +1265,6 @@ var purify = {exports: {}};
|
|
|
1260
1265
|
'mtext'
|
|
1261
1266
|
]);
|
|
1262
1267
|
const HTML_INTEGRATION_POINTS = addToSet({}, [
|
|
1263
|
-
'foreignobject',
|
|
1264
1268
|
'annotation-xml'
|
|
1265
1269
|
]);
|
|
1266
1270
|
// Certain elements are allowed in both SVG and HTML
|
|
@@ -1655,10 +1659,6 @@ var purify = {exports: {}};
|
|
|
1655
1659
|
hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
|
|
1656
1660
|
_executeHook('uponSanitizeAttribute', currentNode, hookEvent);
|
|
1657
1661
|
value = hookEvent.attrValue;
|
|
1658
|
-
/* Work around a security issue with comments inside attributes */ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value)) {
|
|
1659
|
-
_removeAttribute(name, currentNode);
|
|
1660
|
-
continue;
|
|
1661
|
-
}
|
|
1662
1662
|
/* Did the hooks approve of the attribute? */ if (hookEvent.forceKeepAttr) {
|
|
1663
1663
|
continue;
|
|
1664
1664
|
}
|
|
@@ -1691,6 +1691,10 @@ var purify = {exports: {}};
|
|
|
1691
1691
|
// Prefix the value and later re-create the attribute with the sanitized value
|
|
1692
1692
|
value = SANITIZE_NAMED_PROPS_PREFIX + value;
|
|
1693
1693
|
}
|
|
1694
|
+
/* Work around a security issue with comments inside attributes */ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value)) {
|
|
1695
|
+
_removeAttribute(name, currentNode);
|
|
1696
|
+
continue;
|
|
1697
|
+
}
|
|
1694
1698
|
/* Handle attributes that require Trusted Types */ if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
|
|
1695
1699
|
if (namespaceURI) ;
|
|
1696
1700
|
else {
|
|
@@ -2266,6 +2270,19 @@ var purifyExports = purify.exports;
|
|
|
2266
2270
|
return mathml.replace(semanticsStartingTagRegex, "").replace(semanticsEndingTagRegex, "");
|
|
2267
2271
|
}
|
|
2268
2272
|
/**
|
|
2273
|
+
* Removes semantics tag to element that contains mathml.
|
|
2274
|
+
* When using Hand to create formulas, it adds the mrow tag due to the semantics one, this one is also removed.
|
|
2275
|
+
* @param {string} element - Inner HTML text string.
|
|
2276
|
+
* @returns {string} - 'mathml' without semantics tag.
|
|
2277
|
+
*/ static removeSafeXMLSemantics(element) {
|
|
2278
|
+
// If `mrow` is found right before the `semantics` starting tag, it's removed as well
|
|
2279
|
+
const semanticsSafeStartingTagRegex = /«semantics»\s*?(«mrow»)?/gm;
|
|
2280
|
+
// If `mrow` is found right after the `annotation` ending tag, it's removed as well
|
|
2281
|
+
// alongside `semantics` closing tag and the whole `annotation` tag and its contents.
|
|
2282
|
+
const semanticsSafeEndingTagRegex = /(«\/mrow»)?\s*«annotation[\W\w]*?«\/semantics»/gm;
|
|
2283
|
+
return element.replace(semanticsSafeStartingTagRegex, "").replace(semanticsSafeEndingTagRegex, "");
|
|
2284
|
+
}
|
|
2285
|
+
/**
|
|
2269
2286
|
* Transforms all xml mathml occurrences that contain semantics to the same
|
|
2270
2287
|
* xml mathml occurrences without semantics.
|
|
2271
2288
|
* @param {string} text - string that can contain xml mathml occurrences.
|
|
@@ -3588,6 +3605,9 @@ var ko = {
|
|
|
3588
3605
|
var nl = {
|
|
3589
3606
|
latex: "LaTeX",
|
|
3590
3607
|
cancel: "Annuleren",
|
|
3608
|
+
accept: "Invoegen",
|
|
3609
|
+
manual: "Handmatig",
|
|
3610
|
+
insert_math: "Een wiskundige vergelijking invoegen - MathType",
|
|
3591
3611
|
insert_chem: "Een scheikundige formule invoegen - ChemType",
|
|
3592
3612
|
minimize: "Minimaliseer",
|
|
3593
3613
|
maximize: "Maximaliseer",
|
|
@@ -5517,12 +5537,14 @@ var translations = {
|
|
|
5517
5537
|
* @param {string} code - HTML code to be parsed
|
|
5518
5538
|
* @returns {string} HTML code parsed.
|
|
5519
5539
|
*/ static endParseSaveMode(code) {
|
|
5520
|
-
|
|
5521
|
-
|
|
5540
|
+
const savemode = Configuration.get("saveMode");
|
|
5541
|
+
const base64savemode = Configuration.get("base64savemode");
|
|
5542
|
+
if (savemode) {
|
|
5543
|
+
if (savemode === "safeXml") {
|
|
5522
5544
|
code = Parser.codeImgTransform(code, "img2mathml");
|
|
5523
|
-
} else if (
|
|
5545
|
+
} else if (savemode === "xml") {
|
|
5524
5546
|
code = Parser.codeImgTransform(code, "img2mathml");
|
|
5525
|
-
} else if (
|
|
5547
|
+
} else if (savemode === "base64" && base64savemode === "image") {
|
|
5526
5548
|
code = Parser.codeImgTransform(code, "img264");
|
|
5527
5549
|
}
|
|
5528
5550
|
}
|
|
@@ -10769,7 +10791,7 @@ var mathIcon = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!-- Generator: Adob
|
|
|
10769
10791
|
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";
|
|
10770
10792
|
|
|
10771
10793
|
var name = "@wiris/mathtype-ckeditor5";
|
|
10772
|
-
var version = "8.11.
|
|
10794
|
+
var version = "8.11.1";
|
|
10773
10795
|
var description = "MathType Web for CKEditor5 editor";
|
|
10774
10796
|
var keywords = [
|
|
10775
10797
|
"chem",
|
|
@@ -10816,7 +10838,7 @@ var scripts = {
|
|
|
10816
10838
|
prepare: "npm run build:dist"
|
|
10817
10839
|
};
|
|
10818
10840
|
var dependencies = {
|
|
10819
|
-
"@wiris/mathtype-html-integration-devkit": "1.17.
|
|
10841
|
+
"@wiris/mathtype-html-integration-devkit": "1.17.5"
|
|
10820
10842
|
};
|
|
10821
10843
|
var devDependencies = {
|
|
10822
10844
|
"@ckeditor/ckeditor5-dev-build-tools": "^42.1.0",
|
|
@@ -10985,7 +11007,8 @@ class MathType extends Plugin {
|
|
|
10985
11007
|
schema.register("mathml", {
|
|
10986
11008
|
inheritAllFrom: "$inlineObject",
|
|
10987
11009
|
allowAttributes: [
|
|
10988
|
-
"formula"
|
|
11010
|
+
"formula",
|
|
11011
|
+
"htmlContent"
|
|
10989
11012
|
]
|
|
10990
11013
|
});
|
|
10991
11014
|
}
|
|
@@ -11069,6 +11092,50 @@ class MathType extends Plugin {
|
|
|
11069
11092
|
data.modelCursor = data.modelRange.end;
|
|
11070
11093
|
}
|
|
11071
11094
|
});
|
|
11095
|
+
// Data view -> Model
|
|
11096
|
+
editor.data.upcastDispatcher.on("element:img", (evt, data, conversionApi)=>{
|
|
11097
|
+
const { consumable, writer } = conversionApi;
|
|
11098
|
+
const { viewItem } = data;
|
|
11099
|
+
// Only upcast when is wiris formula
|
|
11100
|
+
if (viewItem.getClassNames().next().value !== "Wirisformula") {
|
|
11101
|
+
return;
|
|
11102
|
+
}
|
|
11103
|
+
const mathAttributes = [
|
|
11104
|
+
...viewItem.getAttributes()
|
|
11105
|
+
].map(([key, value])=>` ${key}="${value}"`).join("");
|
|
11106
|
+
let htmlContent = Util.htmlSanitize(`<img${mathAttributes}>`);
|
|
11107
|
+
const modelNode = writer.createElement("mathml", {
|
|
11108
|
+
htmlContent
|
|
11109
|
+
});
|
|
11110
|
+
// Find allowed parent for element that we are going to insert.
|
|
11111
|
+
// If current parent does not allow to insert element but one of the ancestors does
|
|
11112
|
+
// then split nodes to allowed parent.
|
|
11113
|
+
const splitResult = conversionApi.splitToAllowedParent(modelNode, data.modelCursor);
|
|
11114
|
+
// When there is no split result it means that we can't insert element to model tree, so let's skip it.
|
|
11115
|
+
if (!splitResult) {
|
|
11116
|
+
return;
|
|
11117
|
+
}
|
|
11118
|
+
// Insert element on allowed position.
|
|
11119
|
+
conversionApi.writer.insert(modelNode, splitResult.position);
|
|
11120
|
+
// Consume appropriate value from consumable values list.
|
|
11121
|
+
consumable.consume(viewItem, {
|
|
11122
|
+
name: true
|
|
11123
|
+
});
|
|
11124
|
+
const parts = conversionApi.getSplitParts(modelNode);
|
|
11125
|
+
// Set conversion result range.
|
|
11126
|
+
data.modelRange = writer.createRange(conversionApi.writer.createPositionBefore(modelNode), conversionApi.writer.createPositionAfter(parts[parts.length - 1]));
|
|
11127
|
+
// Now we need to check where the `modelCursor` should be.
|
|
11128
|
+
if (splitResult.cursorParent) {
|
|
11129
|
+
// If we split parent to insert our element then we want to continue conversion in the new part of the split parent.
|
|
11130
|
+
//
|
|
11131
|
+
// before: <allowed><notAllowed>foo[]</notAllowed></allowed>
|
|
11132
|
+
// after: <allowed><notAllowed>foo</notAllowed><converted></converted><notAllowed>[]</notAllowed></allowed>
|
|
11133
|
+
data.modelCursor = conversionApi.writer.createPositionAt(splitResult.cursorParent, 0);
|
|
11134
|
+
} else {
|
|
11135
|
+
// Otherwise just continue after inserted element.
|
|
11136
|
+
data.modelCursor = data.modelRange.end;
|
|
11137
|
+
}
|
|
11138
|
+
});
|
|
11072
11139
|
/**
|
|
11073
11140
|
* Whether the given view <math> element has a LaTeX annotation element.
|
|
11074
11141
|
* @param {*} math
|
|
@@ -11097,12 +11164,25 @@ class MathType extends Plugin {
|
|
|
11097
11164
|
}
|
|
11098
11165
|
function createViewImage(modelItem, { writer: viewWriter }) {
|
|
11099
11166
|
const htmlDataProcessor = new HtmlDataProcessor(viewWriter.document);
|
|
11100
|
-
const
|
|
11101
|
-
const
|
|
11102
|
-
|
|
11167
|
+
const formula = modelItem.getAttribute("formula");
|
|
11168
|
+
const htmlContent = modelItem.getAttribute("htmlContent");
|
|
11169
|
+
if (!formula && !htmlContent) {
|
|
11170
|
+
return null;
|
|
11171
|
+
}
|
|
11172
|
+
let imgElement = null;
|
|
11173
|
+
if (htmlContent) {
|
|
11174
|
+
imgElement = htmlDataProcessor.toView(htmlContent).getChild(0);
|
|
11175
|
+
} else if (formula) {
|
|
11176
|
+
const mathString = formula.replaceAll('ref="<"', 'ref="<"');
|
|
11177
|
+
const imgHtml = Parser.initParse(mathString, integration.getLanguage());
|
|
11178
|
+
imgElement = htmlDataProcessor.toView(imgHtml).getChild(0);
|
|
11179
|
+
// Add HTML element (<img>) to model
|
|
11180
|
+
viewWriter.setAttribute("htmlContent", imgHtml, modelItem);
|
|
11181
|
+
}
|
|
11103
11182
|
/* Although we use the HtmlDataProcessor to obtain the attributes,
|
|
11104
|
-
|
|
11105
|
-
|
|
11183
|
+
* we must create a new EmptyElement which is independent of the
|
|
11184
|
+
* DataProcessor being used by this editor instance
|
|
11185
|
+
*/ if (imgElement) {
|
|
11106
11186
|
return viewWriter.createEmptyElement("img", imgElement.getAttributes(), {
|
|
11107
11187
|
renderUnsafeAttributes: [
|
|
11108
11188
|
"src"
|
|
@@ -11143,7 +11223,8 @@ class MathType extends Plugin {
|
|
|
11143
11223
|
}
|
|
11144
11224
|
function createDataString(modelItem, { writer: viewWriter }) {
|
|
11145
11225
|
const htmlDataProcessor = new HtmlDataProcessor(viewWriter.document);
|
|
11146
|
-
|
|
11226
|
+
// Load img element
|
|
11227
|
+
let mathString = modelItem.getAttribute("htmlContent");
|
|
11147
11228
|
const sourceMathElement = htmlDataProcessor.toView(mathString).getChild(0);
|
|
11148
11229
|
return clone(viewWriter, sourceMathElement);
|
|
11149
11230
|
}
|
|
@@ -11155,36 +11236,40 @@ class MathType extends Plugin {
|
|
|
11155
11236
|
* Hack to transform $$latex$$ into <math> in editor.getData()'s output.
|
|
11156
11237
|
*/ editor.data.on("get", (e)=>{
|
|
11157
11238
|
let output = e.return;
|
|
11158
|
-
|
|
11159
|
-
//
|
|
11160
|
-
|
|
11239
|
+
const parsedResult = Parser.endParse(output);
|
|
11240
|
+
// Cleans all the semantics tag for safexml
|
|
11241
|
+
// including the handwritten data points
|
|
11242
|
+
e.return = MathML.removeSafeXMLSemantics(parsedResult);
|
|
11161
11243
|
}, {
|
|
11162
11244
|
priority: "low"
|
|
11163
11245
|
});
|
|
11164
11246
|
/**
|
|
11165
|
-
* Hack to transform <math> with LaTeX into $$LaTeX$$ in editor.setData().
|
|
11247
|
+
* Hack to transform <math> with LaTeX into $$LaTeX$$ and formula images in editor.setData().
|
|
11166
11248
|
*/ editor.data.on("set", (e, args)=>{
|
|
11167
11249
|
// Retrieve the data to be set on the CKEditor.
|
|
11168
11250
|
let modifiedData = args[0];
|
|
11169
11251
|
// Regex to find all mathml formulas.
|
|
11170
|
-
const regexp =
|
|
11171
|
-
|
|
11172
|
-
|
|
11173
|
-
//
|
|
11174
|
-
|
|
11175
|
-
|
|
11176
|
-
|
|
11177
|
-
|
|
11178
|
-
] : [
|
|
11179
|
-
...modifiedData.matchAll(regexp)
|
|
11180
|
-
];
|
|
11181
|
-
// Loop to find LaTeX formulas and replace the MathML for the LaTeX notation.
|
|
11252
|
+
const regexp = /(<img\b[^>]*>)|(<math(.*?)<\/math>)/gm;
|
|
11253
|
+
const formulas = [];
|
|
11254
|
+
let formula;
|
|
11255
|
+
// 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.
|
|
11256
|
+
while((formula = regexp.exec(modifiedData)) !== null){
|
|
11257
|
+
formulas.push(formula[0]);
|
|
11258
|
+
}
|
|
11259
|
+
// Loop to find LaTeX and formula images and replace the MathML for the both.
|
|
11182
11260
|
formulas.forEach((formula)=>{
|
|
11183
|
-
|
|
11184
|
-
if (mathml.includes('encoding="LaTeX"')) {
|
|
11261
|
+
if (formula.includes('encoding="LaTeX"')) {
|
|
11185
11262
|
// LaTeX found.
|
|
11186
|
-
let latex = "$$$" + Latex.getLatexFromMathML(
|
|
11187
|
-
modifiedData = modifiedData.replace(
|
|
11263
|
+
let latex = "$$$" + Latex.getLatexFromMathML(formula) + "$$$"; // We add $$$ instead of $$ because the replace function ignores one $.
|
|
11264
|
+
modifiedData = modifiedData.replace(formula, latex);
|
|
11265
|
+
} else if (formula.includes("<img")) {
|
|
11266
|
+
// If we found a formula image, we should find MathML data, and then substitute the entire image.
|
|
11267
|
+
const regexp = /«math\b[^»]*»(.*?)«\/math»/g;
|
|
11268
|
+
const safexml = formula.match(regexp);
|
|
11269
|
+
if (safexml !== null) {
|
|
11270
|
+
let decodeXML = MathML.safeXmlDecode(safexml[0]);
|
|
11271
|
+
modifiedData = modifiedData.replace(formula, decodeXML);
|
|
11272
|
+
}
|
|
11188
11273
|
}
|
|
11189
11274
|
});
|
|
11190
11275
|
args[0] = modifiedData;
|