@wiris/mathtype-ckeditor5 8.15.1 → 8.15.3
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 +2110 -452
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.umd.js +2110 -452
- package/dist/browser/index.umd.js.map +1 -1
- package/dist/index.js +413 -109
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/integration.js +468 -122
- package/src/plugin.js +64 -6
package/src/plugin.js
CHANGED
|
@@ -446,9 +446,7 @@ export default class MathType extends Plugin {
|
|
|
446
446
|
* DataProcessor being used by this editor instance
|
|
447
447
|
*/
|
|
448
448
|
if (imgElement) {
|
|
449
|
-
return viewWriter.createEmptyElement("img", imgElement.getAttributes()
|
|
450
|
-
renderUnsafeAttributes: ["src"],
|
|
451
|
-
});
|
|
449
|
+
return viewWriter.createEmptyElement("img", imgElement.getAttributes());
|
|
452
450
|
}
|
|
453
451
|
|
|
454
452
|
return null;
|
|
@@ -557,7 +555,7 @@ export default class MathType extends Plugin {
|
|
|
557
555
|
const previewOutput = output.replace(/<img([^>]*class="Wirisformula"[^>]*)>/g, (match, attributes) => {
|
|
558
556
|
// Extract Track Changes attributes
|
|
559
557
|
const trackChangesAttrs = [];
|
|
560
|
-
|
|
558
|
+
|
|
561
559
|
attributesToPreserve.forEach((prefix) => {
|
|
562
560
|
const regex = new RegExp(`(${prefix}[^=]*="[^"]*")`, "g");
|
|
563
561
|
let attrMatch;
|
|
@@ -578,8 +576,11 @@ export default class MathType extends Plugin {
|
|
|
578
576
|
return;
|
|
579
577
|
}
|
|
580
578
|
|
|
581
|
-
//
|
|
582
|
-
const
|
|
579
|
+
// Clean track changes markers only from LaTeX content before converting to MathML.
|
|
580
|
+
const latexParsedOutput = this._endParseEditModeWithTrackChangesSupport(output);
|
|
581
|
+
|
|
582
|
+
// Convert formula images to MathML. It's important to use the save mode to prevent issues.
|
|
583
|
+
const parsedResult = Parser.endParseSaveMode(latexParsedOutput);
|
|
583
584
|
|
|
584
585
|
// Remove all semantic annotations (including handwritten data points)
|
|
585
586
|
// to ensure clean, standard MathML format for storage
|
|
@@ -629,6 +630,45 @@ export default class MathType extends Plugin {
|
|
|
629
630
|
);
|
|
630
631
|
}
|
|
631
632
|
|
|
633
|
+
/**
|
|
634
|
+
* When track changes markers are present inside a LaTeX block:
|
|
635
|
+
* - The LaTeX is preserved as text (not converted to MathML) to maintain suggestions.
|
|
636
|
+
* - It also prevents the issue where the suggestions were placed as MathML tags.
|
|
637
|
+
*
|
|
638
|
+
* When no track changes markers are inside a LaTeX block:
|
|
639
|
+
* - The LaTeX is converted to MathML normally. (previous default behavior)
|
|
640
|
+
*
|
|
641
|
+
* This is to ensure that:
|
|
642
|
+
* 1. LaTeX without suggestions gets converted to MathML for final output.
|
|
643
|
+
* 2. LaTeX with pending suggestions is preserved so setData(getData()) works correctly.
|
|
644
|
+
*/
|
|
645
|
+
_endParseEditModeWithTrackChangesSupport(code) {
|
|
646
|
+
if (!Configuration.get("parseModes").includes("latex")) {
|
|
647
|
+
return code;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
const latexBlockRegex = /\$\$([\s\S]*?)\$\$/g;
|
|
651
|
+
const trackChangesRegex = /<(suggestion|comment)-(start|end)/i;
|
|
652
|
+
|
|
653
|
+
//TODO: Validate if replace all is needed instead of just replace when it is all implemented.
|
|
654
|
+
return code.replace(latexBlockRegex, (fullMatch, latexContent) => {
|
|
655
|
+
// Check if this LaTeX contains track changes markers to prevent conversion.
|
|
656
|
+
if (trackChangesRegex.test(latexContent)) {
|
|
657
|
+
return fullMatch;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
// When LaTeX has no suggestion, it can be converted to MathML.
|
|
661
|
+
const decodedLatex = Util.htmlEntitiesDecode(latexContent);
|
|
662
|
+
let mathml = Util.htmlSanitize(Latex.getMathMLFromLatex(decodedLatex, true));
|
|
663
|
+
|
|
664
|
+
if (!Configuration.get("saveHandTraces")) {
|
|
665
|
+
mathml = MathML.removeAnnotation(mathml, "application/json");
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
return mathml;
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
|
|
632
672
|
/**
|
|
633
673
|
* Expose the WirisPlugin variable to the window
|
|
634
674
|
*/
|
|
@@ -666,6 +706,24 @@ export default class MathType extends Plugin {
|
|
|
666
706
|
(quantity > 1 ? `${quantity} ` : "") +
|
|
667
707
|
StringManager.get(quantity > 1 ? "formulas" : "formula", integration?.getLanguage() || "en"),
|
|
668
708
|
);
|
|
709
|
+
|
|
710
|
+
this._registerLatexTrackChangesAdapter(integration);
|
|
669
711
|
}
|
|
670
712
|
}
|
|
713
|
+
|
|
714
|
+
/**
|
|
715
|
+
* Register a custom adapter for handling LaTeX text changes.
|
|
716
|
+
* This ensures that LaTeX formulas ($$...$$) are treated as atomic units
|
|
717
|
+
* when used by the track changes feature and avoid partial edits.
|
|
718
|
+
*/
|
|
719
|
+
_registerLatexTrackChangesAdapter(integration) {
|
|
720
|
+
const { editor } = this;
|
|
721
|
+
|
|
722
|
+
editor.model.document.on("change:data", () => {
|
|
723
|
+
if (integration) {
|
|
724
|
+
integration._trackChangesEnabled =
|
|
725
|
+
editor.commands.get("trackChanges")?.value ?? false;
|
|
726
|
+
}
|
|
727
|
+
});
|
|
728
|
+
}
|
|
671
729
|
}
|