This commit is contained in:
counterweight 2026-05-14 10:56:04 +02:00
parent bc92231240
commit b8225c639e
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
11904 changed files with 1472749 additions and 133 deletions

View file

@ -0,0 +1,33 @@
import * as DomUtil from '../common/dom_util.js';
import { Attribute } from '../enrich_mathml/enrich_attr.js';
export function splitAttribute(attr) {
return !attr ? [] : attr.split(/,/);
}
export function getAttribute(node, attr) {
return node.getAttribute(attr);
}
export function getSemanticRoot(node) {
if (node.hasAttribute(Attribute.TYPE) &&
!node.hasAttribute(Attribute.PARENT)) {
return node;
}
const semanticNodes = DomUtil.querySelectorAllByAttr(node, Attribute.TYPE);
for (let i = 0, semanticNode; (semanticNode = semanticNodes[i]); i++) {
if (!semanticNode.hasAttribute(Attribute.PARENT)) {
return semanticNode;
}
}
return node;
}
export function getBySemanticId(root, id) {
if (root.getAttribute(Attribute.ID) === id) {
return root;
}
return DomUtil.querySelectorAllByAttrValue(root, Attribute.ID, id)[0];
}
export function getAllBySemanticId(root, id) {
if (root.getAttribute(Attribute.ID) === id) {
return [root];
}
return DomUtil.querySelectorAllByAttrValue(root, Attribute.ID, id);
}