@wiris/mathtype-ckeditor5 8.6.0 → 8.7.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/package.json +2 -2
- package/src/integration.js +5 -2
- package/src/plugin.js +41 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wiris/mathtype-ckeditor5",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.7.1",
|
|
4
4
|
"description": "MathType Web for CKEditor5 editor",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chem",
|
|
@@ -39,6 +39,6 @@
|
|
|
39
39
|
"@ckeditor/ckeditor5-engine": ">=23.0.0",
|
|
40
40
|
"@ckeditor/ckeditor5-ui": ">=23.0.0",
|
|
41
41
|
"@ckeditor/ckeditor5-widget": ">=23.0.0",
|
|
42
|
-
"@wiris/mathtype-html-integration-devkit": "1.14.
|
|
42
|
+
"@wiris/mathtype-html-integration-devkit": "1.14.1"
|
|
43
43
|
}
|
|
44
44
|
}
|
package/src/integration.js
CHANGED
|
@@ -146,9 +146,12 @@ export default class CKEditor5Integration extends IntegrationModel {
|
|
|
146
146
|
// This returns the value returned by the callback function (writer => {...})
|
|
147
147
|
return this.editorObject.model.change((writer) => {
|
|
148
148
|
const core = this.getCore();
|
|
149
|
+
const selection = this.editorObject.model.document.selection;
|
|
149
150
|
|
|
150
|
-
const modelElementNew = writer.createElement('mathml', {
|
|
151
|
-
|
|
151
|
+
const modelElementNew = writer.createElement('mathml', {
|
|
152
|
+
formula: mathml,
|
|
153
|
+
...Object.fromEntries(selection.getAttributes()), // To keep the format, such as style and font
|
|
154
|
+
});
|
|
152
155
|
|
|
153
156
|
// Obtain the DOM <span><img ... /></span> object corresponding to the formula
|
|
154
157
|
if (core.editionProperties.isNewElement) {
|
package/src/plugin.js
CHANGED
|
@@ -257,6 +257,12 @@ export default class MathType extends Plugin {
|
|
|
257
257
|
// And obtain the complete formula
|
|
258
258
|
formula = Util.htmlSanitize(`<math${mathAttributes}>${formula}</math>`);
|
|
259
259
|
|
|
260
|
+
// Replaces the < & > characters to its HTMLEntity to avoid render issues.
|
|
261
|
+
formula = formula.replaceAll('"<"', '"<"')
|
|
262
|
+
.replaceAll('">"', '">"')
|
|
263
|
+
.replaceAll('><<', '><<');
|
|
264
|
+
|
|
265
|
+
|
|
260
266
|
/* Model node that contains what's going to actually be inserted. This can be either:
|
|
261
267
|
- A <mathml> element with a formula attribute set to the given formula, or
|
|
262
268
|
- If the original <math> had a LaTeX annotation, then the annotation surrounded by "$$...$$" */
|
|
@@ -335,7 +341,7 @@ export default class MathType extends Plugin {
|
|
|
335
341
|
function createViewImage(modelItem, { writer: viewWriter }) {
|
|
336
342
|
const htmlDataProcessor = new HtmlDataProcessor(viewWriter.document);
|
|
337
343
|
|
|
338
|
-
const mathString = modelItem.getAttribute('formula').
|
|
344
|
+
const mathString = modelItem.getAttribute('formula').replaceAll('ref="<"', 'ref="<"');
|
|
339
345
|
const imgHtml = Parser.initParse(mathString, editor.config.get('language'));
|
|
340
346
|
const imgElement = htmlDataProcessor.toView(imgHtml).getChild(0);
|
|
341
347
|
|
|
@@ -401,19 +407,51 @@ export default class MathType extends Plugin {
|
|
|
401
407
|
viewToModelPositionOutsideModelElement(editor.model, (viewElement) => viewElement.hasClass('ck-math-widget')),
|
|
402
408
|
);
|
|
403
409
|
|
|
404
|
-
// Keep a reference to the original get function
|
|
405
|
-
const { get } = editor.data;
|
|
410
|
+
// Keep a reference to the original get and set function.
|
|
411
|
+
const { get, set } = editor.data;
|
|
406
412
|
|
|
407
413
|
/**
|
|
408
414
|
* Hack to transform $$latex$$ into <math> in editor.getData()'s output.
|
|
409
415
|
*/
|
|
410
416
|
editor.data.get = (options) => {
|
|
411
417
|
let output = get.bind(editor.data)(options);
|
|
418
|
+
|
|
419
|
+
// CKEditor 5 replaces all the time the < and > for < and >, which our render can't understand.
|
|
420
|
+
// We replace the values inserted for CKEditro5 to be able to render the formulas with the mentioned characters.
|
|
421
|
+
output = output.replaceAll('"<"', '"<"')
|
|
422
|
+
.replaceAll('">"', '">"')
|
|
423
|
+
.replaceAll('><<', '><<');
|
|
424
|
+
|
|
412
425
|
// Ckeditor retrieves editor data and removes the image information on the formulas
|
|
413
426
|
// We transform all the retrieved data to images and then we Parse the data.
|
|
414
427
|
let imageFormula = Parser.initParse(output);
|
|
415
428
|
return Parser.endParse(imageFormula);
|
|
416
429
|
};
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Hack to transform <math> with LaTeX into $$LaTeX$$ in editor.setData().
|
|
433
|
+
*/
|
|
434
|
+
editor.data.set = (data) => {
|
|
435
|
+
// Retrieve the data to be set on the CKEditor.
|
|
436
|
+
let modifiedData = data;
|
|
437
|
+
// Regex to find all mathml formulas.
|
|
438
|
+
const regexp = /<math(.*?)<\/math>/gm;
|
|
439
|
+
|
|
440
|
+
// Get all MathML formulas and store them in an array.
|
|
441
|
+
let formulas = [...data.matchAll(regexp)];
|
|
442
|
+
|
|
443
|
+
// Loop to find LaTeX formulas and replace the MathML for the LaTeX notation.
|
|
444
|
+
formulas.forEach((formula) => {
|
|
445
|
+
let mathml = formula[0];
|
|
446
|
+
if (mathml.includes('encoding="LaTeX"')) { // LaTeX found.
|
|
447
|
+
let latex = '$$$' + Latex.getLatexFromMathML(mathml) + '$$$'; // We add $$$ instead of $$ because the replace function ignores one $.
|
|
448
|
+
modifiedData = modifiedData.replace(mathml, latex);
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
// Run the setData code from CKEditor5 with the modified string.
|
|
453
|
+
set.bind(editor.data)(modifiedData);
|
|
454
|
+
};
|
|
417
455
|
}
|
|
418
456
|
|
|
419
457
|
/**
|