UNPKG

docxml

Version:

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

30 lines (29 loc) 1.15 kB
import { create } from '../utilities/dom.js'; import { QNS } from '../utilities/namespaces.js'; import { evaluateXPathToMap } from '../utilities/xquery.js'; export function tableRowPropertiesFromNode(node) { return node ? evaluateXPathToMap(`map { "isHeaderRow": docxml:ct-on-off(./${QNS.w}tblHeader), "isUnsplittable": docxml:ct-on-off(./${QNS.w}cantSplit), "cellSpacing": docxml:length(${QNS.w}tblCellSpacing[not(@${QNS.w}type = 'nil')]/@${QNS.w}w, 'twip') }`, node) : {}; } export function tableRowPropertiesToNode(tcpr = {}) { if (!Object.keys(tcpr).length) { return null; } return create(`element ${QNS.w}trPr { if ($isHeaderRow) then element ${QNS.w}tblHeader {} else (), if ($isUnsplittable) then element ${QNS.w}cantSplit {} else (), if (exists($cellSpacing)) then element ${QNS.w}tblCellSpacing { attribute ${QNS.w}w { round($cellSpacing('twip')) }, attribute ${QNS.w}type { "dxa" } } else () }`, { isHeaderRow: tcpr.isHeaderRow || false, isUnsplittable: tcpr.isUnsplittable || false, cellSpacing: tcpr.cellSpacing || null, }); }