dwml-ts 0.5.0 → 0.5.2

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.d.ts CHANGED
@@ -20,7 +20,8 @@ export declare function localName(tagName: string): string;
20
20
 
21
21
  /**
22
22
  * Convert an already-parsed `oMath` (or oMath-like) node to bare LaTeX.
23
- * Never throws on unknown constructs.
23
+ * Unwraps `oMathPara` / `a14:m` so display math is not flattened to concatenated
24
+ * `m:t` text (`3/8` → `38`). Never throws on unknown constructs.
24
25
  */
25
26
  export declare function ommlNodeToLatex(node: TNode, options?: OmmlToLatexOptions): string;
26
27
 
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { parse } from "txml/txml";
2
+ import { decodeXML } from "entities";
2
3
  const UNI2LATEX = {
3
4
  34: "''",
4
5
  35: "\\#",
@@ -1946,7 +1947,7 @@ function isElement(node) {
1946
1947
  }
1947
1948
  function textContent(node) {
1948
1949
  let out = '';
1949
- for (const child of node.children)out += 'string' == typeof child ? child : textContent(child);
1950
+ for (const child of node.children)out += 'string' == typeof child ? decodeXML(child) : textContent(child);
1950
1951
  return out;
1951
1952
  }
1952
1953
  function pyFormat(template, positional = [], named = {}) {
@@ -2063,7 +2064,9 @@ const DIRECT_TAGS = new Set([
2063
2064
  'num',
2064
2065
  'den',
2065
2066
  'deg',
2066
- 'e'
2067
+ 'e',
2068
+ 'oMath',
2069
+ 'oMathPara'
2067
2070
  ]);
2068
2071
  class Converter {
2069
2072
  convert(node) {
@@ -2387,7 +2390,17 @@ class Converter {
2387
2390
  }
2388
2391
  const SUB_TEMPLATE = '_{{{0}}}';
2389
2392
  const SUP_TEMPLATE = '^{{{0}}}';
2393
+ function findLocal(node, name, acc = []) {
2394
+ if (localName(node.tagName) === name) acc.push(node);
2395
+ for (const child of node.children)if ('string' != typeof child) findLocal(child, name, acc);
2396
+ return acc;
2397
+ }
2390
2398
  function ommlNodeToLatex(node, options = {}) {
2399
+ const name = localName(node.tagName);
2400
+ if ('oMathPara' === name || 'm' === name) {
2401
+ const found = findLocal(node, 'oMath');
2402
+ if (found.length) return found.map((omath)=>new Converter(options).convert(omath)).join('').trim();
2403
+ }
2391
2404
  return new Converter(options).convert(node);
2392
2405
  }
2393
2406
  function findAll(nodes, name, acc = []) {