File size: 1,173 Bytes
c20f20c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { getTextContent } from '../helpers.js'
import { walker } from '../walker.js'

export function mroot(element, targetParent, previousSibling, nextSibling, ancestors) {
  // Root
  if (element.children.length !== 2) {
    // treat as mrow
    return targetParent
  }
  ancestors = [...ancestors]
  ancestors.unshift(element)
  const base = element.children[0]
  const root = element.children[1]

  const baseTarget = {
    type: 'tag',
    name: 'm:e',
    attribs: {},
    children: []
  }
  walker(base, baseTarget, false, false, ancestors)

  const rootTarget = {
    type: 'tag',
    name: 'm:deg',
    attribs: {},
    children: []
  }
  walker(root, rootTarget, false, false, ancestors)

  const rootText = getTextContent(root)

  targetParent.children.push({
    type: 'tag',
    name: 'm:rad',
    attribs: {},
    children: [
      {
        type: 'tag',
        name: 'm:radPr',
        attribs: {},
        children: [
          {
            type: 'tag',
            name: 'm:degHide',
            attribs: { 'm:val': rootText.length ? 'off' : 'on' },
            children: []
          }
        ]
      },
      rootTarget,
      baseTarget
    ]
  })
}