Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,6 @@ dist/

# Temporary folders
tmp/
temp/
temp/

example.docx
6 changes: 3 additions & 3 deletions example/example-node.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable no-console */
const fs = require('fs');
import fs from 'fs';
// FIXME: Incase you have the npm package
// const HTMLtoDOCX = require('html-to-docx');
const HTMLtoDOCX = require('../dist/html-to-docx.umd');
//import HTMLtoDOCX from 'html-to-docx';
import HTMLtoDOCX from '../index.js';

const filePath = './example.docx';

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-useless-escape */
import JSZip from 'jszip';
import addFilesToContainer from './src/html-to-docx';
import addFilesToContainer from './src/html-to-docx.js';

const minifyHTMLString = (htmlString) => {
try {
Expand Down
257 changes: 133 additions & 124 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"office",
"word"
],
"main": "dist/html-to-docx.umd.js",
"module": "dist/html-to-docx.esm.js",
"type": "module",
"module": "index.js",
"scripts": {
"test": "npm run build && node example/example-node.js",
"test": "node example/example-node.js",
"prerelease": "rollup -c",
"release": "standard-version",
"lint": "eslint --fix .",
Expand Down Expand Up @@ -52,30 +52,30 @@
"@rollup/plugin-commonjs": "^12.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.1.1",
"@rollup/plugin-terser": "^0.4.4",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.0",
"lint-staged": "^11.1.2",
"lodash-es": "^4.17.21",
"prettier": "^2.4.1",
"rollup": "^2.62.0",
"rollup-plugin-cleaner": "^1.0.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-terser": "^7.0.2",
"standard-version": "^9.3.1"
},
"dependencies": {
"@oozcitak/util": "8.3.4",
"@oozcitak/dom": "1.15.6",
"@oozcitak/util": "8.3.4",
"color-name": "^1.1.4",
"html-entities": "^2.3.3",
"html-to-vdom": "^0.7.0",
"image-size": "^1.0.0",
"image-to-base64": "^2.2.0",
"jszip": "^3.7.1",
"lodash": "^4.17.21",
"mime-types": "^2.1.35",
"nanoid": "^3.1.25",
"virtual-dom": "^2.1.1",
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { nodeResolve as resolve } from '@rollup/plugin-node-resolve';
import json from '@rollup/plugin-json';
import commonjs from '@rollup/plugin-commonjs';
import { terser } from 'rollup-plugin-terser';
import terser from '@rollup/plugin-terser';
import cleaner from 'rollup-plugin-cleaner';
import builtins from 'rollup-plugin-node-builtins';

Expand Down
2 changes: 1 addition & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloneDeep } from 'lodash';
import { cloneDeep } from 'lodash-es';

const applicationName = 'html-to-docx';
const defaultOrientation = 'portrait';
Expand Down
12 changes: 6 additions & 6 deletions src/docx-document.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {
fontTableXML as fontTableXMLString,
genericRelsXML as genericRelsXMLString,
generateDocumentTemplate,
} from './schemas';
import { convertVTreeToXML } from './helpers';
import namespaces from './namespaces';
} from './schemas/index.js';
import { convertVTreeToXML } from './helpers/index.js';
import namespaces from './namespaces.js';
import {
footerType as footerFileType,
headerType as headerFileType,
Expand All @@ -33,9 +33,9 @@ import {
documentFileName,
imageType,
defaultDocumentOptions,
} from './constants';
import ListStyleBuilder from './utils/list';
import { fontFamilyToTableObject } from './utils/font-family-conversion';
} from './constants.js';
import ListStyleBuilder from './utils/list.js';
import { fontFamilyToTableObject } from './utils/font-family-conversion.js';

function generateContentTypesFragments(contentTypesXML, type, objects) {
if (objects && Array.isArray(objects)) {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* eslint-disable import/prefer-default-export */
export { default as renderDocumentFile } from './render-document-file';
export { convertVTreeToXML } from './render-document-file';
export { default as renderDocumentFile } from './render-document-file.js';
export { convertVTreeToXML } from './render-document-file.js';
18 changes: 9 additions & 9 deletions src/helpers/render-document-file.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable no-case-declarations */
import { fragment } from 'xmlbuilder2';
import VNode from 'virtual-dom/vnode/vnode';
import VText from 'virtual-dom/vnode/vtext';
import isVNode from 'virtual-dom/vnode/is-vnode';
import isVText from 'virtual-dom/vnode/is-vtext';
import VNode from 'virtual-dom/vnode/vnode.js';
import VText from 'virtual-dom/vnode/vtext.js';
import isVNode from 'virtual-dom/vnode/is-vnode.js';
import isVText from 'virtual-dom/vnode/is-vtext.js';
// eslint-disable-next-line import/no-named-default
import { default as HTMLToVDOM } from 'html-to-vdom';
import sizeOf from 'image-size';
Expand All @@ -13,11 +13,11 @@ import mimeTypes from 'mime-types';

// FIXME: remove the cyclic dependency
// eslint-disable-next-line import/no-cycle
import * as xmlBuilder from './xml-builder';
import namespaces from '../namespaces';
import { imageType, internalRelationship } from '../constants';
import { vNodeHasChildren } from '../utils/vnode';
import { isValidUrl } from '../utils/url';
import * as xmlBuilder from './xml-builder.js';
import namespaces from '../namespaces.js';
import { imageType, internalRelationship } from '../constants.js';
import { vNodeHasChildren } from '../utils/vnode.js';
import { isValidUrl } from '../utils/url.js';

const convertHTML = HTMLToVDOM({
VNode,
Expand Down
20 changes: 10 additions & 10 deletions src/helpers/xml-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
/* eslint-disable no-plusplus */
/* eslint-disable no-else-return */
import { fragment } from 'xmlbuilder2';
import isVNode from 'virtual-dom/vnode/is-vnode';
import isVText from 'virtual-dom/vnode/is-vtext';
import isVNode from 'virtual-dom/vnode/is-vnode.js';
import isVText from 'virtual-dom/vnode/is-vtext.js';
import colorNames from 'color-name';
import { cloneDeep } from 'lodash';
import { cloneDeep } from 'lodash-es';
import imageToBase64 from 'image-to-base64';
import mimeTypes from 'mime-types';
import sizeOf from 'image-size';

import namespaces from '../namespaces';
import namespaces from '../namespaces.js';
import {
rgbToHex,
hslToHex,
Expand All @@ -22,7 +22,7 @@ import {
hexRegex,
hex3Regex,
hex3ToHex,
} from '../utils/color-conversion';
} from '../utils/color-conversion.js';
import {
pixelToEMU,
pixelRegex,
Expand All @@ -40,10 +40,10 @@ import {
cmRegex,
inchRegex,
inchToTWIP,
} from '../utils/unit-conversion';
} from '../utils/unit-conversion.js';
// FIXME: remove the cyclic dependency
// eslint-disable-next-line import/no-cycle
import { buildImage, buildList } from './render-document-file';
import { buildImage, buildList } from './render-document-file.js';
import {
defaultFont,
hyperlinkType,
Expand All @@ -52,9 +52,9 @@ import {
verticalAlignValues,
imageType,
internalRelationship,
} from '../constants';
import { vNodeHasChildren } from '../utils/vnode';
import { isValidUrl } from '../utils/url';
} from '../constants.js';
import { vNodeHasChildren } from '../utils/vnode.js';
import { isValidUrl } from '../utils/url.js';

// eslint-disable-next-line consistent-return
const fixupColorCode = (colorCodeString) => {
Expand Down
14 changes: 7 additions & 7 deletions src/html-to-docx.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { create } from 'xmlbuilder2';
import VNode from 'virtual-dom/vnode/vnode';
import VText from 'virtual-dom/vnode/vtext';
import VNode from 'virtual-dom/vnode/vnode.js';
import VText from 'virtual-dom/vnode/vtext.js';
// eslint-disable-next-line import/no-named-default
import { default as HTMLToVDOM } from 'html-to-vdom';
import { decode } from 'html-entities';

import { relsXML } from './schemas';
import DocxDocument from './docx-document';
import { renderDocumentFile } from './helpers';
import { relsXML } from './schemas/index.js';
import DocxDocument from './docx-document.js';
import { renderDocumentFile } from './helpers/index.js';
import {
pixelRegex,
pixelToTWIP,
Expand All @@ -17,7 +17,7 @@ import {
inchToTWIP,
pointRegex,
pointToHIP,
} from './utils/unit-conversion';
} from './utils/unit-conversion.js';
import {
defaultDocumentOptions,
defaultHTMLString,
Expand All @@ -32,7 +32,7 @@ import {
wordFolder,
themeFolder,
themeType,
} from './constants';
} from './constants.js';

const convertHTML = HTMLToVDOM({
VNode,
Expand Down
4 changes: 2 additions & 2 deletions src/schemas/core.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import namespaces from '../namespaces';
import { applicationName } from '../constants';
import namespaces from '../namespaces.js';
import { applicationName } from '../constants.js';

const generateCoreXML = (
title = '',
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/document-rels.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import namespaces from '../namespaces';
import namespaces from '../namespaces.js';

const documentRelsXML = `
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/document.template.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import namespaces from '../namespaces';
import namespaces from '../namespaces.js';

const generateDocumentTemplate = (width, height, orientation, margins) => `
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/font-table.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import namespaces from '../namespaces';
import namespaces from '../namespaces.js';

// Font data available here: https://fossies.org/linux/pandoc/data/docx/word/fontTable.xml
const fontTableXML = `
Expand Down
24 changes: 12 additions & 12 deletions src/schemas/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export { default as contentTypesXML } from './content-types';
export { default as generateCoreXML } from './core';
export { default as documentRelsXML } from './document-rels';
export { default as relsXML } from './rels';
export { default as generateNumberingXMLTemplate } from './numbering';
export { default as generateStylesXML } from './styles';
export { default as fontTableXML } from './font-table';
export { default as generateThemeXML } from './theme';
export { default as settingsXML } from './settings';
export { default as webSettingsXML } from './web-settings';
export { default as genericRelsXML } from './generic-rels';
export { default as generateDocumentTemplate } from './document.template';
export { default as contentTypesXML } from './content-types.js';
export { default as generateCoreXML } from './core.js';
export { default as documentRelsXML } from './document-rels.js';
export { default as relsXML } from './rels.js';
export { default as generateNumberingXMLTemplate } from './numbering.js';
export { default as generateStylesXML } from './styles.js';
export { default as fontTableXML } from './font-table.js';
export { default as generateThemeXML } from './theme.js';
export { default as settingsXML } from './settings.js';
export { default as webSettingsXML } from './web-settings.js';
export { default as genericRelsXML } from './generic-rels.js';
export { default as generateDocumentTemplate } from './document.template.js';
2 changes: 1 addition & 1 deletion src/schemas/numbering.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import namespaces from '../namespaces';
import namespaces from '../namespaces.js';

const generateNumberingXMLTemplate = () => `
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/rels.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import namespaces from '../namespaces';
import namespaces from '../namespaces.js';

const relsXML = `
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/settings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import namespaces from '../namespaces';
import namespaces from '../namespaces.js';

const settingsXML = `
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
Expand Down
4 changes: 2 additions & 2 deletions src/schemas/styles.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defaultFont, defaultFontSize, defaultLang } from '../constants';
import namespaces from '../namespaces';
import { defaultFont, defaultFontSize, defaultLang } from '../constants.js';
import namespaces from '../namespaces.js';

const generateStylesXML = (
font = defaultFont,
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/theme.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defaultFont } from '../constants';
import { defaultFont } from '../constants.js';

const generateThemeXML = (font = defaultFont) => `
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/web-settings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import namespaces from '../namespaces';
import namespaces from '../namespaces.js';

const webSettingsXML = `
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
Expand Down