UNPKG

docxml

Version:

TypeScript (component) library for building and parsing a DOCX file

53 lines (52 loc) 1.47 kB
import { Component } from '../classes/Component.js'; import { registerComponent } from '../utilities/components.js'; import { create } from '../utilities/dom.js'; import { QNS } from '../utilities/namespaces.js'; import { evaluateXPathToMap } from '../utilities/xquery.js'; /** * The start of a range associated with a comment. */ export class CommentRangeStart extends Component { /** * Creates an XML DOM node for this component instance. */ // eslint-disable-next-line @typescript-eslint/no-unused-vars toNode(_ancestry) { return create(` element ${QNS.w}commentRangeStart { attribute ${QNS.w}id { $id } } `, { id: this.props.id, }); } /** * Asserts whether or not a given XML node correlates with this component. */ static matchesNode(node) { return node.nodeName === 'w:commentRangeStart'; } /** * Instantiate this component from the XML in an existing DOCX file. */ static fromNode(node) { return new CommentRangeStart(evaluateXPathToMap(` map { "id": ./@${QNS.w}id/number() } `, node)); } } Object.defineProperty(CommentRangeStart, "children", { enumerable: true, configurable: true, writable: true, value: [] }); Object.defineProperty(CommentRangeStart, "mixed", { enumerable: true, configurable: true, writable: true, value: false }); registerComponent(CommentRangeStart);