UNPKG

docxml

Version:

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

52 lines (51 loc) 1.57 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 BookmarkRangeStart 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}bookmarkStart { attribute ${QNS.w}id { $id }, attribute ${QNS.w}name { $name } }`, this.props.bookmark || { id: this.props.id, name: this.props.name, }); } /** * Asserts whether or not a given XML node correlates with this component. */ static matchesNode(node) { return node.nodeName === 'w:bookmarkStart'; } /** * Instantiate this component from the XML in an existing DOCX file. */ static fromNode(node) { return new BookmarkRangeStart(evaluateXPathToMap(`map { "id": ./@${QNS.w}id/number(), "name": ./@${QNS.w}name/string() }`, node)); } } Object.defineProperty(BookmarkRangeStart, "children", { enumerable: true, configurable: true, writable: true, value: [] }); Object.defineProperty(BookmarkRangeStart, "mixed", { enumerable: true, configurable: true, writable: true, value: false }); registerComponent(BookmarkRangeStart);