@lofcz/pptxtojson 2.2.5 → 2.2.6

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.js CHANGED
@@ -2700,10 +2700,25 @@ function findOMath(obj) {
2700
2700
  });
2701
2701
  return results;
2702
2702
  }
2703
+ function localName(tag) {
2704
+ if (!tag) return '';
2705
+ const i = tag.indexOf(':');
2706
+ return i >= 0 ? tag.slice(i + 1) : tag;
2707
+ }
2708
+ function firstRawOMath(node) {
2709
+ if (!node || 'object' != typeof node) return null;
2710
+ if ('oMath' === localName(node.tagName)) return node;
2711
+ for (const child of node.children || [])if ('object' == typeof child) {
2712
+ const found = firstRawOMath(child);
2713
+ if (found) return found;
2714
+ }
2715
+ return null;
2716
+ }
2703
2717
  function oMathToLatex(simplifiedNode) {
2704
2718
  const rawNode = simplifiedNode && simplifiedNode.__rawNode;
2705
2719
  if (!rawNode) return '';
2706
- return latexFormart(ommlNodeToLatex(rawNode)).trim();
2720
+ const math = firstRawOMath(rawNode) || rawNode;
2721
+ return latexFormart(ommlNodeToLatex(math)).trim();
2707
2722
  }
2708
2723
  const toArray = (value)=>{
2709
2724
  if (!value) return [];
@@ -2711,6 +2726,17 @@ const toArray = (value)=>{
2711
2726
  value
2712
2727
  ];
2713
2728
  };
2729
+ function mathPayloads(container) {
2730
+ const direct = toArray(container && container['m:oMath']);
2731
+ if (direct.length) return direct;
2732
+ const out = [];
2733
+ for (const para of toArray(container && container['m:oMathPara'])){
2734
+ const inner = toArray(para['m:oMath']);
2735
+ if (inner.length) out.push(...inner);
2736
+ else out.push(para);
2737
+ }
2738
+ return out;
2739
+ }
2714
2740
  function getInlineMathRuns(pNode) {
2715
2741
  const runs = [];
2716
2742
  const push = (node, order)=>{
@@ -2726,15 +2752,9 @@ function getInlineMathRuns(pNode) {
2726
2752
  };
2727
2753
  for (const wrapper of toArray(pNode['a14:m'])){
2728
2754
  const order = wrapper && wrapper.attrs && wrapper.attrs.order || 0;
2729
- for (const key of [
2730
- 'm:oMath',
2731
- 'm:oMathPara'
2732
- ])for (const node of toArray(wrapper[key]))push(node, order);
2733
- }
2734
- for (const key of [
2735
- 'm:oMath',
2736
- 'm:oMathPara'
2737
- ])for (const node of toArray(pNode[key]))push(node, node && node.attrs && node.attrs.order || 0);
2755
+ for (const node of mathPayloads(wrapper))push(node, order);
2756
+ }
2757
+ for (const node of mathPayloads(pNode))push(node, node && node.attrs && node.attrs.order || 0);
2738
2758
  return runs;
2739
2759
  }
2740
2760
  const findMathRunPr = (node, skipCtrlPr)=>{