UNPKG

docxml

Version:

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

59 lines (58 loc) 1.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Break = void 0; const Component_js_1 = require("../classes/Component.js"); const components_js_1 = require("../utilities/components.js"); const dom_js_1 = require("../utilities/dom.js"); const namespaces_js_1 = require("../utilities/namespaces.js"); const xquery_js_1 = require("../utilities/xquery.js"); /** * A component that represents a line break, page break or section break in a DOCX document. Place * this in one of the `<Text>`, `<TextAddition>` or `<TextDeletion>` components. */ class Break extends Component_js_1.Component { /** * Creates an XML DOM node for this component instance. */ // eslint-disable-next-line @typescript-eslint/no-unused-vars toNode(_ancestry) { return (0, dom_js_1.create)(` element ${namespaces_js_1.QNS.w}br { if (exists($type)) then attribute ${namespaces_js_1.QNS.w}type { $type } else (), if (exists($clear)) then attribute ${namespaces_js_1.QNS.w}clear { $clear } else () } `, { type: this.props.type || null, clear: this.props.clear || null, }); } /** * Asserts whether or not a given XML node correlates with this component. */ static matchesNode(node) { return node.nodeName === 'w:br'; } /** * Instantiate this component from the XML in an existing DOCX file. */ static fromNode(node) { return new Break((0, xquery_js_1.evaluateXPathToMap)(`map { "type": ./@${namespaces_js_1.QNS.w}type/string(), "clear": ./@${namespaces_js_1.QNS.w}clear/string() }`, node)); } } exports.Break = Break; Object.defineProperty(Break, "children", { enumerable: true, configurable: true, writable: true, value: [] }); Object.defineProperty(Break, "mixed", { enumerable: true, configurable: true, writable: true, value: false }); (0, components_js_1.registerComponent)(Break);