@pie-lib/editable-html 10.0.7-next.10 → 10.0.7

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/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [10.0.7](https://github.com/pie-framework/pie-lib/compare/@pie-lib/editable-html@10.0.6...@pie-lib/editable-html@10.0.7) (2023-09-18)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * use the mathMl resulted no matter if new latex is not identical; added a function to fix the round branckets issue ([61eeaed](https://github.com/pie-framework/pie-lib/commit/61eeaedc240bc247842a0164c07e58a8d8d792c9))
12
+ * **editable-html:** Disable HTML mode in player & retain html mode on alert dialog cancel PD-2765 ([4c56092](https://github.com/pie-framework/pie-lib/commit/4c56092bc66ebde1571b42419c563c580c68b927))
13
+
14
+
15
+
16
+
17
+
6
18
  ## [10.0.6](https://github.com/pie-framework/pie-lib/compare/@pie-lib/editable-html@10.0.5...@pie-lib/editable-html@10.0.6) (2023-09-14)
7
19
 
8
20
  **Note:** Version bump only for package @pie-lib/editable-html
@@ -269,6 +269,12 @@ var lessThanHandling = function lessThanHandling(input) {
269
269
  return input;
270
270
  };
271
271
 
272
+ function fixLatexExpression(latexInput) {
273
+ // for some reason, mmlToLatex parses () incorrectly - or at least in a way that our interpreter can not use them
274
+ // Replace '\\left.' and '\\right.' with an empty string
275
+ return latexInput.replace(/\\left\.\s*|\\right\.\s*/g, '');
276
+ }
277
+
272
278
  var serialization = {
273
279
  deserialize: function deserialize(el) {
274
280
  var tagName = getTagName(el);
@@ -292,8 +298,9 @@ var serialization = {
292
298
  if (MathPlugin.mathMlOptions.mmlEditing) {
293
299
  var htmlToUse = (0, _mathRendering.mmlToLatex)(newHtml);
294
300
  var latex = htmlDecode(htmlToUse);
301
+ var correctedLatex = fixLatexExpression(latex);
295
302
 
296
- var _unWrapMath = (0, _mathRendering.unWrapMath)(latex),
303
+ var _unWrapMath = (0, _mathRendering.unWrapMath)(correctedLatex),
297
304
  unwrapped = _unWrapMath.unwrapped,
298
305
  wrapType = _unWrapMath.wrapType;
299
306
 
@@ -364,21 +371,24 @@ var serialization = {
364
371
  var strippedNewL = newLatex.replace(/\s/g, ''); // we check if the latex keeps his form after being converted to mathml and back to latex
365
372
  // if it does we can safely convert it to mathml
366
373
 
367
- if ((0, _isEqual["default"])(strippedL, strippedNewL)) {
368
- return /*#__PURE__*/_react["default"].createElement("span", {
369
- "data-type": "mathml",
370
- dangerouslySetInnerHTML: {
371
- __html: res
372
- }
373
- });
374
- } else {
374
+ if (!(0, _isEqual["default"])(strippedL, strippedNewL)) {
375
+ var correctedLatex = fixLatexExpression(newLatex); // As George requested in PD-3167, I will set the new mathML anyway, and also log differences
375
376
  // if it doesn't we keep the latex version
377
+
376
378
  console.log('This latex can not be safely converted to mathml so we will keep the latex version!!!', {
377
379
  initialLatex: l,
378
380
  newLatex: newLatex,
381
+ correctedLatex: correctedLatex,
379
382
  mathML: res
380
383
  });
381
384
  }
385
+
386
+ return /*#__PURE__*/_react["default"].createElement("span", {
387
+ "data-type": "mathml",
388
+ dangerouslySetInnerHTML: {
389
+ __html: res
390
+ }
391
+ });
382
392
  }
383
393
 
384
394
  return /*#__PURE__*/_react["default"].createElement("span", {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/plugins/math/index.jsx"],"names":["log","TEXT_NODE","generateAdditionalKeys","keyData","map","key","name","latex","write","label","CustomToolbarComp","React","memo","props","node","value","onFocus","onBlur","onClick","pluginProps","math","keypadMode","customKeys","controlledKeypadMode","onDone","update","data","toObject","change","setNodeByKey","nextText","document","getNextText","moveFocusTo","moveAnchorTo","onToolbarDone","onChange","onDataChange","get","prev","next","nodeNext","keypadModeNext","controlledKeypadModeNext","keypadModeChanged","controlledKeypadModeChanged","equal","equals","propTypes","SlatePropTypes","isRequired","PropTypes","func","MathPlugin","opts","mathMlOptions","mmlOutput","mmlEditing","toolbar","icon","inlineMath","insertInline","supports","object","type","schema","match","pluginStyles","parentNode","p","position","top","renderNode","html","attributes","__html","ROUND_BRACKETS","SQUARE_BRACKETS","DOLLAR","DOUBLE_DOLLAR","Inline","create","isVoid","htmlDecode","input","doc","DOMParser","parseFromString","documentElement","textContent","getTagName","el","tagName","toLowerCase","lessThanHandling","arrowSplit","split","length","reduce","st","part","serialization","deserialize","hasMathChild","BLOCK_TAGS","childNodes","firstChild","dataset","newHtml","innerHTML","outerHTML","htmlToUse","unwrapped","wrapType","nodes","wrapper","nodeType","hasLatex","hasAttribute","serialize","l","decoded","res","newLatex","strippedL","replace","strippedNewL","console","initialLatex","mathML"],"mappings":";;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,qCAAN,CAAZ;AAEA,IAAMC,SAAS,GAAG,CAAlB;;AAEA,SAASC,sBAAT,GAA8C;AAAA,MAAdC,OAAc,uEAAJ,EAAI;AAC5C,SAAOA,OAAO,CAACC,GAAR,CAAY,UAACC,GAAD;AAAA,WAAU;AAC3BC,MAAAA,IAAI,EAAED,GADqB;AAE3BE,MAAAA,KAAK,EAAEF,GAFoB;AAG3BG,MAAAA,KAAK,EAAEH,GAHoB;AAI3BI,MAAAA,KAAK,EAAEJ;AAJoB,KAAV;AAAA,GAAZ,CAAP;AAMD,C,CAED;;;AACO,IAAMK,iBAAiB,gBAAGC,kBAAMC,IAAN,CAC/B,UAACC,KAAD,EAAW;AACT,MAAQC,IAAR,GAAkDD,KAAlD,CAAQC,IAAR;AAAA,MAAcC,KAAd,GAAkDF,KAAlD,CAAcE,KAAd;AAAA,MAAqBC,OAArB,GAAkDH,KAAlD,CAAqBG,OAArB;AAAA,MAA8BC,MAA9B,GAAkDJ,KAAlD,CAA8BI,MAA9B;AAAA,MAAsCC,OAAtC,GAAkDL,KAAlD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,uBAAuB,EAAE;AAAEqC,UAAAA,MAAM,EAAEF;AAAV;AAAlD,QAAP;AACD;AACF;AApH0B,CAAtB","sourcesContent":["import Functions from '@material-ui/icons/Functions';\nimport { Inline } from 'slate';\nimport { MathPreview, MathToolbar } from '@pie-lib/math-toolbar';\nimport { wrapMath, unWrapMath, mmlToLatex, renderMath } from '@pie-lib/math-rendering';\nimport React from 'react';\nimport debug from 'debug';\nimport SlatePropTypes from 'slate-prop-types';\nimport PropTypes from 'prop-types';\n\nimport { BLOCK_TAGS } from '../../serialization';\nimport isEqual from 'lodash/isEqual';\n\nconst log = debug('@pie-lib:editable-html:plugins:math');\n\nconst TEXT_NODE = 3;\n\nfunction generateAdditionalKeys(keyData = []) {\n return keyData.map((key) => ({\n name: key,\n latex: key,\n write: key,\n label: key,\n }));\n}\n\n// eslint-disable-next-line react/display-name\nexport const CustomToolbarComp = React.memo(\n (props) => {\n const { node, value, onFocus, onBlur, onClick } = props;\n const { pluginProps } = props || {};\n const { math } = pluginProps || {};\n const { keypadMode, customKeys, controlledKeypadMode = true } = math || {};\n\n const onDone = (latex) => {\n const update = {\n ...node.data.toObject(),\n latex,\n };\n const change = value.change().setNodeByKey(node.key, { data: update });\n\n const nextText = value.document.getNextText(node.key);\n\n change.moveFocusTo(nextText.key, 0).moveAnchorTo(nextText.key, 0);\n\n props.onToolbarDone(change, false);\n };\n\n const onChange = (latex) => {\n const update = {\n ...node.data.toObject(),\n latex,\n };\n const change = value.change().setNodeByKey(node.key, { data: update });\n log('call onToolbarChange:', change);\n props.onDataChange(node.key, update);\n };\n\n const latex = node.data.get('latex');\n\n return (\n <MathToolbar\n autoFocus\n additionalKeys={generateAdditionalKeys(customKeys)}\n latex={latex}\n onChange={onChange}\n onDone={onDone}\n onBlur={onBlur}\n onFocus={onFocus}\n onClick={onClick}\n keypadMode={keypadMode}\n controlledKeypadMode={controlledKeypadMode}\n />\n );\n },\n (prev, next) => {\n const { node, pluginProps: { math: { keypadMode, controlledKeypadMode } = {} } = {} } = prev;\n const {\n node: nodeNext,\n pluginProps: { math: { keypadMode: keypadModeNext, controlledKeypadMode: controlledKeypadModeNext } = {} } = {},\n } = next;\n const keypadModeChanged = keypadMode !== keypadModeNext;\n const controlledKeypadModeChanged = controlledKeypadMode !== controlledKeypadModeNext;\n\n const equal = node.equals(nodeNext);\n return equal && !keypadModeChanged && !controlledKeypadModeChanged;\n },\n);\n\nCustomToolbarComp.propTypes = {\n node: SlatePropTypes.node.isRequired,\n value: SlatePropTypes.value,\n onToolbarDone: PropTypes.func,\n onDataChange: PropTypes.func,\n onFocus: PropTypes.func,\n onClick: PropTypes.func,\n onBlur: PropTypes.func,\n};\n\nexport default function MathPlugin(opts) {\n MathPlugin.mathMlOptions = {\n mmlOutput: opts.mmlOutput,\n mmlEditing: opts.mmlEditing,\n };\n\n return {\n name: 'math',\n toolbar: {\n icon: <Functions />,\n onClick: (value, onChange) => {\n log('[insertMath]');\n const math = inlineMath();\n const change = value.change().insertInline(math);\n onChange(change);\n },\n supports: (node) => node && node.object === 'inline' && node.type === 'math',\n /**\n * Return a react component function\n * @param node {Slate.Node}\n * @param value {Slate.Value}\n * @param onDone {(change?: Slate.Change, finishEditing :boolea) => void} - a function to call once the toolbar\n * has made any changes, call with the node.key and a data object.\n */\n CustomToolbarComp,\n },\n schema: {\n document: { match: [{ type: 'math' }] },\n },\n\n pluginStyles: (node, parentNode, p) => {\n if (p) {\n return {\n position: 'absolute',\n top: 'initial',\n };\n }\n },\n\n renderNode: (props) => {\n if (props.node.type === 'math') {\n log('[renderNode]: data:', props.node.data);\n return <MathPreview {...props} />;\n }\n\n /**\n * Here for rendering mathml content\n */\n if (props.node.type === 'mathml') {\n const html = props.node.data.get('html');\n\n return <span {...props.attributes} dangerouslySetInnerHTML={{ __html: html }} />;\n }\n },\n };\n}\n\nMathPlugin.ROUND_BRACKETS = 'round_brackets';\nMathPlugin.SQUARE_BRACKETS = 'square_brackets';\nMathPlugin.DOLLAR = 'dollar';\nMathPlugin.DOUBLE_DOLLAR = 'double_dollar';\nMathPlugin.mathMlOptions = {};\n\nMathPlugin.propTypes = {\n attributes: PropTypes.object,\n node: SlatePropTypes.node,\n};\n\nexport const inlineMath = () =>\n Inline.create({\n object: 'inline',\n type: 'math',\n isVoid: true,\n data: {\n latex: '',\n },\n });\n\nconst htmlDecode = (input) => {\n const doc = new DOMParser().parseFromString(input, 'text/html');\n\n return doc.documentElement.textContent;\n};\n\nconst getTagName = (el) => {\n return ((el && el.tagName) || '').toLowerCase();\n};\n\n/**\n * Makes sure that strings that contain stuff like:\n * x<y are not transformed into x by the DOMParser because it thinks\n * that <y is the start of a dom element tag\n * @param input\n * @returns {*}\n */\nconst lessThanHandling = (input) => {\n const arrowSplit = input.split('<');\n\n // if we don't have at least 2 characters there's no point in checking\n if (input.length > 2) {\n return arrowSplit.reduce((st, part) => {\n /*\n We check if this element resulted is:\n div - continuation of a beginning of a HTML element\n /div - closing of a HTML tag\n br/> - beginning and closing of a html TAG\n */\n if (part.match(/<[a-zA-Z/][\\s\\S]*>/gi)) {\n return `${st}${st ? '<' : ''}${part}`;\n }\n\n return `${st}${st ? '&lt;' : ''}${part}`;\n }, '');\n }\n\n return input;\n};\n\nexport const serialization = {\n deserialize(el) {\n const tagName = getTagName(el);\n /**\n * This is used for when there's a wrapper over the mathml element.\n * Because of this slate rule: \"Only allow block nodes or inline and text nodes in blocks.\"\n * The element that contains only the mathml is removed (along with the math) because it has\n * an inline child and the block is of type block\n * This is for legacy content only since our math rendering is valid for the core slate rules\n */\n const hasMathChild = BLOCK_TAGS[tagName] && el.childNodes.length === 1 && getTagName(el.firstChild) === 'math';\n log('[deserialize] name: ', tagName);\n\n /**\n * This is here in order to be able to render mathml content\n */\n if (tagName === 'math' || (el.dataset && el.dataset.type === 'mathml') || hasMathChild) {\n const newHtml = hasMathChild ? el.innerHTML : el.outerHTML;\n\n if (MathPlugin.mathMlOptions.mmlEditing) {\n const htmlToUse = mmlToLatex(newHtml);\n const latex = htmlDecode(htmlToUse);\n const { unwrapped, wrapType } = unWrapMath(latex);\n\n return {\n object: 'inline',\n type: 'math',\n isVoid: true,\n nodes: [],\n data: {\n latex: unwrapped,\n wrapper: wrapType,\n },\n };\n }\n\n return {\n object: 'inline',\n isVoid: true,\n type: 'mathml',\n data: {\n html: newHtml,\n },\n };\n }\n\n if (el.nodeType === TEXT_NODE) {\n return;\n }\n\n if (tagName !== 'span') {\n return;\n }\n\n const hasLatex = el.hasAttribute('data-latex') || el.hasAttribute('latex');\n\n if (hasLatex) {\n const latex = htmlDecode(el.innerHTML);\n const { unwrapped, wrapType } = unWrapMath(latex);\n log('[deserialize]: noBrackets: ', unwrapped, wrapType);\n return {\n object: 'inline',\n type: 'math',\n isVoid: true,\n nodes: [],\n data: {\n latex: unwrapped,\n wrapper: wrapType,\n },\n };\n }\n },\n serialize(object) {\n if (object.type === 'math') {\n const l = object.data.get('latex');\n const wrapper = object.data.get('wrapper');\n log('[serialize] latex: ', l);\n const decoded = htmlDecode(lessThanHandling(l));\n\n if (MathPlugin.mathMlOptions.mmlOutput) {\n const res = renderMath(`<span data-latex=\"\" data-raw=\"${decoded}\">${wrapMath(decoded, wrapper)}</span>`);\n const newLatex = mmlToLatex(res);\n\n // we need to remove all the spaces from the latex to be able to compare it\n const strippedL = l.replace(/\\s/g, '');\n const strippedNewL = newLatex.replace(/\\s/g, '');\n\n // we check if the latex keeps his form after being converted to mathml and back to latex\n // if it does we can safely convert it to mathml\n if (isEqual(strippedL, strippedNewL)) {\n return <span data-type=\"mathml\" dangerouslySetInnerHTML={{ __html: res }} />;\n } else {\n // if it doesn't we keep the latex version\n console.log('This latex can not be safely converted to mathml so we will keep the latex version!!!', {\n initialLatex: l,\n newLatex: newLatex,\n mathML: res,\n });\n }\n }\n\n return (\n <span data-latex=\"\" data-raw={decoded}>\n {wrapMath(decoded, wrapper)}\n </span>\n );\n }\n\n /**\n * Here for rendering mathml content\n */\n if (object.type === 'mathml') {\n const html = object.data.get('html');\n\n return <span data-type=\"mathml\" dangerouslySetInnerHTML={{ __html: html }} />;\n }\n },\n};\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../src/plugins/math/index.jsx"],"names":["log","TEXT_NODE","generateAdditionalKeys","keyData","map","key","name","latex","write","label","CustomToolbarComp","React","memo","props","node","value","onFocus","onBlur","onClick","pluginProps","math","keypadMode","customKeys","controlledKeypadMode","onDone","update","data","toObject","change","setNodeByKey","nextText","document","getNextText","moveFocusTo","moveAnchorTo","onToolbarDone","onChange","onDataChange","get","prev","next","nodeNext","keypadModeNext","controlledKeypadModeNext","keypadModeChanged","controlledKeypadModeChanged","equal","equals","propTypes","SlatePropTypes","isRequired","PropTypes","func","MathPlugin","opts","mathMlOptions","mmlOutput","mmlEditing","toolbar","icon","inlineMath","insertInline","supports","object","type","schema","match","pluginStyles","parentNode","p","position","top","renderNode","html","attributes","__html","ROUND_BRACKETS","SQUARE_BRACKETS","DOLLAR","DOUBLE_DOLLAR","Inline","create","isVoid","htmlDecode","input","doc","DOMParser","parseFromString","documentElement","textContent","getTagName","el","tagName","toLowerCase","lessThanHandling","arrowSplit","split","length","reduce","st","part","fixLatexExpression","latexInput","replace","serialization","deserialize","hasMathChild","BLOCK_TAGS","childNodes","firstChild","dataset","newHtml","innerHTML","outerHTML","htmlToUse","correctedLatex","unwrapped","wrapType","nodes","wrapper","nodeType","hasLatex","hasAttribute","serialize","l","decoded","res","newLatex","strippedL","strippedNewL","console","initialLatex","mathML"],"mappings":";;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,qCAAN,CAAZ;AAEA,IAAMC,SAAS,GAAG,CAAlB;;AAEA,SAASC,sBAAT,GAA8C;AAAA,MAAdC,OAAc,uEAAJ,EAAI;AAC5C,SAAOA,OAAO,CAACC,GAAR,CAAY,UAACC,GAAD;AAAA,WAAU;AAC3BC,MAAAA,IAAI,EAAED,GADqB;AA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R,EAAmBC,YAAnB,CAAL,EAAuC;AACrC,cAAMd,cAAc,GAAGd,kBAAkB,CAAC0B,QAAD,CAAzC,CADqC,CAGrC;AACA;;AACAG,UAAAA,OAAO,CAAClI,GAAR,CAAY,uFAAZ,EAAqG;AACnGmI,YAAAA,YAAY,EAAEP,CADqF;AAEnGG,YAAAA,QAAQ,EAAEA,QAFyF;AAGnGZ,YAAAA,cAAc,EAAdA,cAHmG;AAInGiB,YAAAA,MAAM,EAAEN;AAJ2F,WAArG;AAMD;;AAED,4BAAO;AAAM,uBAAU,QAAhB;AAAyB,UAAA,uBAAuB,EAAE;AAAEnD,YAAAA,MAAM,EAAEmD;AAAV;AAAlD,UAAP;AACD;;AAED,0BACE;AAAM,sBAAW,EAAjB;AAAoB,oBAAUD;AAA9B,SACG,6BAASA,OAAT,EAAkBN,OAAlB,CADH,CADF;AAKD;AAED;AACJ;AACA;;;AACI,QAAIxD,MAAM,CAACC,IAAP,KAAgB,QAApB,EAA8B;AAC5B,UAAMS,IAAI,GAAGV,MAAM,CAACrC,IAAP,CAAYY,GAAZ,CAAgB,MAAhB,CAAb;AAEA,0BAAO;AAAM,qBAAU,QAAhB;AAAyB,QAAA,uBAAuB,EAAE;AAAEqC,UAAAA,MAAM,EAAEF;AAAV;AAAlD,QAAP;AACD;AACF;AAzH0B,CAAtB","sourcesContent":["import Functions from '@material-ui/icons/Functions';\nimport { Inline } from 'slate';\nimport { MathPreview, MathToolbar } from '@pie-lib/math-toolbar';\nimport { wrapMath, unWrapMath, mmlToLatex, renderMath } from '@pie-lib/math-rendering';\nimport React from 'react';\nimport debug from 'debug';\nimport SlatePropTypes from 'slate-prop-types';\nimport PropTypes from 'prop-types';\n\nimport { BLOCK_TAGS } from '../../serialization';\nimport isEqual from 'lodash/isEqual';\n\nconst log = debug('@pie-lib:editable-html:plugins:math');\n\nconst TEXT_NODE = 3;\n\nfunction generateAdditionalKeys(keyData = []) {\n return keyData.map((key) => ({\n name: key,\n latex: key,\n write: key,\n label: key,\n }));\n}\n\n// eslint-disable-next-line react/display-name\nexport const CustomToolbarComp = React.memo(\n (props) => {\n const { node, value, onFocus, onBlur, onClick } = props;\n const { pluginProps } = props || {};\n const { math } = pluginProps || {};\n const { keypadMode, customKeys, controlledKeypadMode = true } = math || {};\n\n const onDone = (latex) => {\n const update = {\n ...node.data.toObject(),\n latex,\n };\n const change = value.change().setNodeByKey(node.key, { data: update });\n\n const nextText = value.document.getNextText(node.key);\n\n change.moveFocusTo(nextText.key, 0).moveAnchorTo(nextText.key, 0);\n\n props.onToolbarDone(change, false);\n };\n\n const onChange = (latex) => {\n const update = {\n ...node.data.toObject(),\n latex,\n };\n const change = value.change().setNodeByKey(node.key, { data: update });\n log('call onToolbarChange:', change);\n props.onDataChange(node.key, update);\n };\n\n const latex = node.data.get('latex');\n\n return (\n <MathToolbar\n autoFocus\n additionalKeys={generateAdditionalKeys(customKeys)}\n latex={latex}\n onChange={onChange}\n onDone={onDone}\n onBlur={onBlur}\n onFocus={onFocus}\n onClick={onClick}\n keypadMode={keypadMode}\n controlledKeypadMode={controlledKeypadMode}\n />\n );\n },\n (prev, next) => {\n const { node, pluginProps: { math: { keypadMode, controlledKeypadMode } = {} } = {} } = prev;\n const {\n node: nodeNext,\n pluginProps: { math: { keypadMode: keypadModeNext, controlledKeypadMode: controlledKeypadModeNext } = {} } = {},\n } = next;\n const keypadModeChanged = keypadMode !== keypadModeNext;\n const controlledKeypadModeChanged = controlledKeypadMode !== controlledKeypadModeNext;\n\n const equal = node.equals(nodeNext);\n return equal && !keypadModeChanged && !controlledKeypadModeChanged;\n },\n);\n\nCustomToolbarComp.propTypes = {\n node: SlatePropTypes.node.isRequired,\n value: SlatePropTypes.value,\n onToolbarDone: PropTypes.func,\n onDataChange: PropTypes.func,\n onFocus: PropTypes.func,\n onClick: PropTypes.func,\n onBlur: PropTypes.func,\n};\n\nexport default function MathPlugin(opts) {\n MathPlugin.mathMlOptions = {\n mmlOutput: opts.mmlOutput,\n mmlEditing: opts.mmlEditing,\n };\n\n return {\n name: 'math',\n toolbar: {\n icon: <Functions />,\n onClick: (value, onChange) => {\n log('[insertMath]');\n const math = inlineMath();\n const change = value.change().insertInline(math);\n onChange(change);\n },\n supports: (node) => node && node.object === 'inline' && node.type === 'math',\n /**\n * Return a react component function\n * @param node {Slate.Node}\n * @param value {Slate.Value}\n * @param onDone {(change?: Slate.Change, finishEditing :boolea) => void} - a function to call once the toolbar\n * has made any changes, call with the node.key and a data object.\n */\n CustomToolbarComp,\n },\n schema: {\n document: { match: [{ type: 'math' }] },\n },\n\n pluginStyles: (node, parentNode, p) => {\n if (p) {\n return {\n position: 'absolute',\n top: 'initial',\n };\n }\n },\n\n renderNode: (props) => {\n if (props.node.type === 'math') {\n log('[renderNode]: data:', props.node.data);\n return <MathPreview {...props} />;\n }\n\n /**\n * Here for rendering mathml content\n */\n if (props.node.type === 'mathml') {\n const html = props.node.data.get('html');\n\n return <span {...props.attributes} dangerouslySetInnerHTML={{ __html: html }} />;\n }\n },\n };\n}\n\nMathPlugin.ROUND_BRACKETS = 'round_brackets';\nMathPlugin.SQUARE_BRACKETS = 'square_brackets';\nMathPlugin.DOLLAR = 'dollar';\nMathPlugin.DOUBLE_DOLLAR = 'double_dollar';\nMathPlugin.mathMlOptions = {};\n\nMathPlugin.propTypes = {\n attributes: PropTypes.object,\n node: SlatePropTypes.node,\n};\n\nexport const inlineMath = () =>\n Inline.create({\n object: 'inline',\n type: 'math',\n isVoid: true,\n data: {\n latex: '',\n },\n });\n\nconst htmlDecode = (input) => {\n const doc = new DOMParser().parseFromString(input, 'text/html');\n\n return doc.documentElement.textContent;\n};\n\nconst getTagName = (el) => {\n return ((el && el.tagName) || '').toLowerCase();\n};\n\n/**\n * Makes sure that strings that contain stuff like:\n * x<y are not transformed into x by the DOMParser because it thinks\n * that <y is the start of a dom element tag\n * @param input\n * @returns {*}\n */\nconst lessThanHandling = (input) => {\n const arrowSplit = input.split('<');\n\n // if we don't have at least 2 characters there's no point in checking\n if (input.length > 2) {\n return arrowSplit.reduce((st, part) => {\n /*\n We check if this element resulted is:\n div - continuation of a beginning of a HTML element\n /div - closing of a HTML tag\n br/> - beginning and closing of a html TAG\n */\n if (part.match(/<[a-zA-Z/][\\s\\S]*>/gi)) {\n return `${st}${st ? '<' : ''}${part}`;\n }\n\n return `${st}${st ? '&lt;' : ''}${part}`;\n }, '');\n }\n\n return input;\n};\n\nfunction fixLatexExpression(latexInput) {\n // for some reason, mmlToLatex parses () incorrectly - or at least in a way that our interpreter can not use them\n // Replace '\\\\left.' and '\\\\right.' with an empty string\n return latexInput.replace(/\\\\left\\.\\s*|\\\\right\\.\\s*/g, '');\n}\n\nexport const serialization = {\n deserialize(el) {\n const tagName = getTagName(el);\n /**\n * This is used for when there's a wrapper over the mathml element.\n * Because of this slate rule: \"Only allow block nodes or inline and text nodes in blocks.\"\n * The element that contains only the mathml is removed (along with the math) because it has\n * an inline child and the block is of type block\n * This is for legacy content only since our math rendering is valid for the core slate rules\n */\n const hasMathChild = BLOCK_TAGS[tagName] && el.childNodes.length === 1 && getTagName(el.firstChild) === 'math';\n log('[deserialize] name: ', tagName);\n\n /**\n * This is here in order to be able to render mathml content\n */\n if (tagName === 'math' || (el.dataset && el.dataset.type === 'mathml') || hasMathChild) {\n const newHtml = hasMathChild ? el.innerHTML : el.outerHTML;\n\n if (MathPlugin.mathMlOptions.mmlEditing) {\n const htmlToUse = mmlToLatex(newHtml);\n const latex = htmlDecode(htmlToUse);\n const correctedLatex = fixLatexExpression(latex);\n const { unwrapped, wrapType } = unWrapMath(correctedLatex);\n\n return {\n object: 'inline',\n type: 'math',\n isVoid: true,\n nodes: [],\n data: {\n latex: unwrapped,\n wrapper: wrapType,\n },\n };\n }\n\n return {\n object: 'inline',\n isVoid: true,\n type: 'mathml',\n data: {\n html: newHtml,\n },\n };\n }\n\n if (el.nodeType === TEXT_NODE) {\n return;\n }\n\n if (tagName !== 'span') {\n return;\n }\n\n const hasLatex = el.hasAttribute('data-latex') || el.hasAttribute('latex');\n\n if (hasLatex) {\n const latex = htmlDecode(el.innerHTML);\n const { unwrapped, wrapType } = unWrapMath(latex);\n log('[deserialize]: noBrackets: ', unwrapped, wrapType);\n return {\n object: 'inline',\n type: 'math',\n isVoid: true,\n nodes: [],\n data: {\n latex: unwrapped,\n wrapper: wrapType,\n },\n };\n }\n },\n serialize(object) {\n if (object.type === 'math') {\n const l = object.data.get('latex');\n const wrapper = object.data.get('wrapper');\n log('[serialize] latex: ', l);\n const decoded = htmlDecode(lessThanHandling(l));\n\n if (MathPlugin.mathMlOptions.mmlOutput) {\n const res = renderMath(`<span data-latex=\"\" data-raw=\"${decoded}\">${wrapMath(decoded, wrapper)}</span>`);\n const newLatex = mmlToLatex(res);\n\n // we need to remove all the spaces from the latex to be able to compare it\n const strippedL = l.replace(/\\s/g, '');\n const strippedNewL = newLatex.replace(/\\s/g, '');\n\n // we check if the latex keeps his form after being converted to mathml and back to latex\n // if it does we can safely convert it to mathml\n if (!isEqual(strippedL, strippedNewL)) {\n const correctedLatex = fixLatexExpression(newLatex);\n\n // As George requested in PD-3167, I will set the new mathML anyway, and also log differences\n // if it doesn't we keep the latex version\n console.log('This latex can not be safely converted to mathml so we will keep the latex version!!!', {\n initialLatex: l,\n newLatex: newLatex,\n correctedLatex,\n mathML: res,\n });\n }\n\n return <span data-type=\"mathml\" dangerouslySetInnerHTML={{ __html: res }} />;\n }\n\n return (\n <span data-latex=\"\" data-raw={decoded}>\n {wrapMath(decoded, wrapper)}\n </span>\n );\n }\n\n /**\n * Here for rendering mathml content\n */\n if (object.type === 'mathml') {\n const html = object.data.get('html');\n\n return <span data-type=\"mathml\" dangerouslySetInnerHTML={{ __html: html }} />;\n }\n },\n};\n"],"file":"index.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-lib/editable-html",
3
- "version": "10.0.7-next.10+b4ffbee0",
3
+ "version": "10.0.7",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "main": "lib/index.js",
@@ -51,6 +51,6 @@
51
51
  "publishConfig": {
52
52
  "access": "public"
53
53
  },
54
- "gitHead": "b4ffbee0840334f1ccd6c52f6b8e8de3a084e9f6",
54
+ "gitHead": "cfece677af97481eb28f18a152dfe80ad471b63f",
55
55
  "scripts": {}
56
56
  }
@@ -214,6 +214,12 @@ const lessThanHandling = (input) => {
214
214
  return input;
215
215
  };
216
216
 
217
+ function fixLatexExpression(latexInput) {
218
+ // for some reason, mmlToLatex parses () incorrectly - or at least in a way that our interpreter can not use them
219
+ // Replace '\\left.' and '\\right.' with an empty string
220
+ return latexInput.replace(/\\left\.\s*|\\right\.\s*/g, '');
221
+ }
222
+
217
223
  export const serialization = {
218
224
  deserialize(el) {
219
225
  const tagName = getTagName(el);
@@ -236,7 +242,8 @@ export const serialization = {
236
242
  if (MathPlugin.mathMlOptions.mmlEditing) {
237
243
  const htmlToUse = mmlToLatex(newHtml);
238
244
  const latex = htmlDecode(htmlToUse);
239
- const { unwrapped, wrapType } = unWrapMath(latex);
245
+ const correctedLatex = fixLatexExpression(latex);
246
+ const { unwrapped, wrapType } = unWrapMath(correctedLatex);
240
247
 
241
248
  return {
242
249
  object: 'inline',
@@ -303,16 +310,20 @@ export const serialization = {
303
310
 
304
311
  // we check if the latex keeps his form after being converted to mathml and back to latex
305
312
  // if it does we can safely convert it to mathml
306
- if (isEqual(strippedL, strippedNewL)) {
307
- return <span data-type="mathml" dangerouslySetInnerHTML={{ __html: res }} />;
308
- } else {
313
+ if (!isEqual(strippedL, strippedNewL)) {
314
+ const correctedLatex = fixLatexExpression(newLatex);
315
+
316
+ // As George requested in PD-3167, I will set the new mathML anyway, and also log differences
309
317
  // if it doesn't we keep the latex version
310
318
  console.log('This latex can not be safely converted to mathml so we will keep the latex version!!!', {
311
319
  initialLatex: l,
312
320
  newLatex: newLatex,
321
+ correctedLatex,
313
322
  mathML: res,
314
323
  });
315
324
  }
325
+
326
+ return <span data-type="mathml" dangerouslySetInnerHTML={{ __html: res }} />;
316
327
  }
317
328
 
318
329
  return (