File size: 1,452 Bytes
f56a29b | 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 | import { getTextContent } from '../helpers.js'
const NARY_REGEXP = /^[\u220f-\u2211]|[\u2229-\u2233]|[\u22c0-\u22c3]$/
const GROW_REGEXP = /^\u220f|\u2211|[\u2229-\u222b]|\u222e|\u222f|\u2232|\u2233|[\u22c0-\u22c3]$/
export function getNary(node) {
// Check if node contains only a nary operator.
const text = getTextContent(node)
if (NARY_REGEXP.test(text)) {
return text
}
return false
}
export function getNaryTarget(naryChar, element, type, subHide = false, supHide = false) {
const stretchy = element.attribs?.stretchy
const grow =
stretchy === 'true' ? '1' : stretchy === 'false' ? '0' : GROW_REGEXP.test(naryChar) ? '1' : '0'
return {
type: 'tag',
name: 'm:nary',
attribs: {},
children: [
{
type: 'tag',
name: 'm:naryPr',
attribs: {},
children: [
{ type: 'tag', name: 'm:chr', attribs: { 'm:val': naryChar }, children: [] },
{ type: 'tag', name: 'm:limLoc', attribs: { 'm:val': type }, children: [] },
{ type: 'tag', name: 'm:grow', attribs: { 'm:val': grow }, children: [] },
{
type: 'tag',
name: 'm:subHide',
attribs: { 'm:val': subHide ? 'on' : 'off' },
children: []
},
{
type: 'tag',
name: 'm:supHide',
attribs: { 'm:val': supHide ? 'on' : 'off' },
children: []
}
]
}
]
}
}
|