Skip to content

Commit

Permalink
feat: added document file render helper
Browse files Browse the repository at this point in the history
  • Loading branch information
privateOmega committed May 28, 2020
1 parent f13b5cc commit 6dd9c3a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/helpers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* eslint-disable import/prefer-default-export */
export { default as renderDocumentFile } from './render-document-file';
40 changes: 40 additions & 0 deletions src/helpers/render-document-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { fragment } from 'xmlbuilder2';

import template from '../../template/document.template';

const VNode = require('virtual-dom/vnode/vnode');
const VText = require('virtual-dom/vnode/vtext');

const convertHTML = require('html-to-vdom')({
VNode,
VText,
});

// eslint-disable-next-line no-unused-vars
function convertVTreeToXML(vNode, xmlFragment) {
if (!vNode) {
// eslint-disable-next-line no-useless-return
return;
}
// eslint-disable-next-line no-empty
if (vNode.type === 'VirtualText') {
}
}

function renderDocumentFile(documentOptions, htmlString) {
const { orientation, margins } = documentOptions;
const width = orientation === 'landscape' ? 15840 : 12240;
const height = orientation === 'landscape' ? 12240 : 15840;

// eslint-disable-next-line no-unused-vars
const vTree = convertHTML(htmlString);

const xmlFragment = fragment();

// eslint-disable-next-line no-unused-vars
const xmlString = convertVTreeToXML(vTree, xmlFragment);

return template(width, height, orientation, margins);
}

export default renderDocumentFile;
1 change: 1 addition & 0 deletions src/html-to-docx.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { contentTypesXML, generateCoreXML, generateDocumentRelsXML, relsXML } from './schemas';
import { renderDocumentFile } from './helpers';

const defaultDocumentOptions = {
orientation: 'portrait',
Expand Down

0 comments on commit 6dd9c3a

Please sign in to comment.