Skip to content

Commit

Permalink
fix: updated xml builder to use namespace and child nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
privateOmega committed May 28, 2020
1 parent c34810f commit 2e28b5e
Show file tree
Hide file tree
Showing 2 changed files with 235 additions and 90 deletions.
20 changes: 14 additions & 6 deletions src/helpers/render-document-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ const convertHTML = require('html-to-vdom')({
function findXMLEquivalent(docxDocumentInstance, vNode, xmlFragment) {
switch (vNode.tagName) {
case 'p':
xmlBuilder.buildParagraph(xmlFragment, vNode);
// eslint-disable-next-line no-case-declarations
const paragraphFragment = xmlBuilder.buildParagraph(vNode);
xmlFragment.import(paragraphFragment);
return;
case 'table':
xmlBuilder.buildTable(xmlFragment, vNode);
// eslint-disable-next-line no-case-declarations
const tableFragment = xmlBuilder.buildTable(vNode);
xmlFragment.import(tableFragment);
return;
case 'ol':
case 'ul':
Expand All @@ -29,9 +33,11 @@ function findXMLEquivalent(docxDocumentInstance, vNode, xmlFragment) {
for (let index = 0; index < vNode.children.length; index++) {
const childVNode = vNode.children[index];
if (childVNode.tagName === 'li') {
xmlBuilder.buildParagraph(xmlFragment, childVNode, {
// eslint-disable-next-line no-shadow
const paragraphFragment = xmlBuilder.buildParagraph(childVNode, {
numbering: { levelId: 0, numberingId },
});
xmlFragment.import(paragraphFragment);
}
}
return;
Expand Down Expand Up @@ -73,11 +79,13 @@ function renderDocumentFile(docxDocumentInstance) {
// eslint-disable-next-line no-unused-vars
const vTree = convertHTML(docxDocumentInstance.htmlString);

const xmlFragment = fragment();
const xmlFragment = fragment({
namespaceAlias: { w: 'http://schemas.openxmlformats.org/wordprocessingml/2006/main' },
});

const xmlString = convertVTreeToXML(docxDocumentInstance, vTree, xmlFragment);
const populatedXmlFragment = convertVTreeToXML(docxDocumentInstance, vTree, xmlFragment);

return xmlString;
return populatedXmlFragment;
}

export default renderDocumentFile;
Loading

0 comments on commit 2e28b5e

Please sign in to comment.