@lofcz/pptxtojson 2.2.5 → 2.2.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/dist/index.cjs CHANGED
@@ -2732,10 +2732,25 @@ function findOMath(obj) {
2732
2732
  });
2733
2733
  return results;
2734
2734
  }
2735
+ function localName(tag) {
2736
+ if (!tag) return '';
2737
+ const i = tag.indexOf(':');
2738
+ return i >= 0 ? tag.slice(i + 1) : tag;
2739
+ }
2740
+ function firstRawOMath(node) {
2741
+ if (!node || 'object' != typeof node) return null;
2742
+ if ('oMath' === localName(node.tagName)) return node;
2743
+ for (const child of node.children || [])if ('object' == typeof child) {
2744
+ const found = firstRawOMath(child);
2745
+ if (found) return found;
2746
+ }
2747
+ return null;
2748
+ }
2735
2749
  function oMathToLatex(simplifiedNode) {
2736
2750
  const rawNode = simplifiedNode && simplifiedNode.__rawNode;
2737
2751
  if (!rawNode) return '';
2738
- return latexFormart((0, external_dwml_ts_namespaceObject.ommlNodeToLatex)(rawNode)).trim();
2752
+ const math = firstRawOMath(rawNode) || rawNode;
2753
+ return latexFormart((0, external_dwml_ts_namespaceObject.ommlNodeToLatex)(math)).trim();
2739
2754
  }
2740
2755
  const toArray = (value)=>{
2741
2756
  if (!value) return [];
@@ -2743,6 +2758,17 @@ const toArray = (value)=>{
2743
2758
  value
2744
2759
  ];
2745
2760
  };
2761
+ function mathPayloads(container) {
2762
+ const direct = toArray(container && container['m:oMath']);
2763
+ if (direct.length) return direct;
2764
+ const out = [];
2765
+ for (const para of toArray(container && container['m:oMathPara'])){
2766
+ const inner = toArray(para['m:oMath']);
2767
+ if (inner.length) out.push(...inner);
2768
+ else out.push(para);
2769
+ }
2770
+ return out;
2771
+ }
2746
2772
  function getInlineMathRuns(pNode) {
2747
2773
  const runs = [];
2748
2774
  const push = (node, order)=>{
@@ -2758,15 +2784,9 @@ function getInlineMathRuns(pNode) {
2758
2784
  };
2759
2785
  for (const wrapper of toArray(pNode['a14:m'])){
2760
2786
  const order = wrapper && wrapper.attrs && wrapper.attrs.order || 0;
2761
- for (const key of [
2762
- 'm:oMath',
2763
- 'm:oMathPara'
2764
- ])for (const node of toArray(wrapper[key]))push(node, order);
2765
- }
2766
- for (const key of [
2767
- 'm:oMath',
2768
- 'm:oMathPara'
2769
- ])for (const node of toArray(pNode[key]))push(node, node && node.attrs && node.attrs.order || 0);
2787
+ for (const node of mathPayloads(wrapper))push(node, order);
2788
+ }
2789
+ for (const node of mathPayloads(pNode))push(node, node && node.attrs && node.attrs.order || 0);
2770
2790
  return runs;
2771
2791
  }
2772
2792
  const findMathRunPr = (node, skipCtrlPr)=>{