walker_util.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.splitAttribute = splitAttribute;
  4. exports.getAttribute = getAttribute;
  5. exports.getSemanticRoot = getSemanticRoot;
  6. exports.getBySemanticId = getBySemanticId;
  7. exports.getAllBySemanticId = getAllBySemanticId;
  8. const DomUtil = require("../common/dom_util.js");
  9. const enrich_attr_js_1 = require("../enrich_mathml/enrich_attr.js");
  10. function splitAttribute(attr) {
  11. return !attr ? [] : attr.split(/,/);
  12. }
  13. function getAttribute(node, attr) {
  14. return node.getAttribute(attr);
  15. }
  16. function getSemanticRoot(node) {
  17. if (node.hasAttribute(enrich_attr_js_1.Attribute.TYPE) &&
  18. !node.hasAttribute(enrich_attr_js_1.Attribute.PARENT)) {
  19. return node;
  20. }
  21. const semanticNodes = DomUtil.querySelectorAllByAttr(node, enrich_attr_js_1.Attribute.TYPE);
  22. for (let i = 0, semanticNode; (semanticNode = semanticNodes[i]); i++) {
  23. if (!semanticNode.hasAttribute(enrich_attr_js_1.Attribute.PARENT)) {
  24. return semanticNode;
  25. }
  26. }
  27. return node;
  28. }
  29. function getBySemanticId(root, id) {
  30. if (root.getAttribute(enrich_attr_js_1.Attribute.ID) === id) {
  31. return root;
  32. }
  33. return DomUtil.querySelectorAllByAttrValue(root, enrich_attr_js_1.Attribute.ID, id)[0];
  34. }
  35. function getAllBySemanticId(root, id) {
  36. if (root.getAttribute(enrich_attr_js_1.Attribute.ID) === id) {
  37. return [root];
  38. }
  39. return DomUtil.querySelectorAllByAttrValue(root, enrich_attr_js_1.Attribute.ID, id);
  40. }