@adobe/helix-md2docx 1.2.3 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [1.3.0](https://github.com/adobe/helix-md2docx/compare/v1.2.3...v1.3.0) (2022-02-02)
2
+
3
+
4
+ ### Features
5
+
6
+ * allow to provide styles.xml ([e01c784](https://github.com/adobe/helix-md2docx/commit/e01c78458ab7270fd9924f32767df1f204689e5b))
7
+
1
8
  ## [1.2.3](https://github.com/adobe/helix-md2docx/compare/v1.2.2...v1.2.3) (2022-01-25)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-md2docx",
3
- "version": "1.2.3",
3
+ "version": "1.3.0",
4
4
  "description": "Helix Service that converts markdown to word documents",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -35,7 +35,7 @@
35
35
  "hast-util-is-element": "2.1.2",
36
36
  "hast-util-to-mdast": "8.3.0",
37
37
  "image-size": "1.0.1",
38
- "rehype-parse": "8.0.3",
38
+ "rehype-parse": "8.0.4",
39
39
  "remark-gfm": "3.0.1",
40
40
  "remark-parse": "10.0.1",
41
41
  "unified": "10.1.1",
@@ -43,25 +43,26 @@
43
43
  },
44
44
  "devDependencies": {
45
45
  "@adobe/eslint-config-helix": "1.3.2",
46
- "@adobe/helix-mediahandler": "1.0.2",
46
+ "@adobe/helix-mediahandler": "1.0.3",
47
47
  "@semantic-release/changelog": "6.0.1",
48
48
  "@semantic-release/exec": "6.0.3",
49
49
  "@semantic-release/git": "10.0.1",
50
50
  "c8": "7.11.0",
51
- "chai": "4.3.4",
51
+ "chai": "4.3.6",
52
52
  "codecov": "3.8.3",
53
- "dotenv": "14.2.0",
54
- "eslint": "8.7.0",
53
+ "dotenv": "14.3.2",
54
+ "eslint": "8.8.0",
55
55
  "eslint-plugin-header": "3.1.1",
56
56
  "eslint-plugin-import": "2.25.4",
57
57
  "fs-extra": "10.0.0",
58
58
  "husky": "7.0.4",
59
59
  "junit-report-builder": "3.0.0",
60
- "lint-staged": "12.2.2",
61
- "mocha": "9.1.4",
60
+ "lint-staged": "12.3.2",
61
+ "mocha": "9.2.0",
62
62
  "mocha-multi-reporters": "1.5.1",
63
63
  "semantic-release": "19.0.2",
64
- "unist-util-inspect": "7.0.0"
64
+ "unist-util-inspect": "7.0.0",
65
+ "yauzl": "2.10.0"
65
66
  },
66
67
  "lint-staged": {
67
68
  "*.js": "eslint"
@@ -15,12 +15,12 @@ import gfm from 'remark-gfm';
15
15
  import { remarkMatter } from '@adobe/helix-markdown-support';
16
16
  import mdast2docx from '../mdast2docx/index.js';
17
17
 
18
- export default async function md2docx(md, log = console) {
18
+ export default async function md2docx(md, log = console, stylesXML = null) {
19
19
  const mdast = unified()
20
20
  .use(remark, { position: false })
21
21
  .use(gfm)
22
22
  .use(remarkMatter)
23
23
  .parse(md);
24
24
 
25
- return mdast2docx(mdast, log);
25
+ return mdast2docx(mdast, log, stylesXML);
26
26
  }
@@ -24,10 +24,7 @@ import downloadImages from './mdast-download-images.js';
24
24
 
25
25
  const { Document, Packer } = docx;
26
26
 
27
- // eslint-disable-next-line no-underscore-dangle
28
- const __dirname = url.fileURLToPath ? path.dirname(url.fileURLToPath(import.meta.url)) : './';
29
-
30
- export default async function mdast2docx(mdast, log = console) {
27
+ export default async function mdast2docx(mdast, log = console, stylesXML = null) {
31
28
  const ctx = {
32
29
  handlers,
33
30
  style: {},
@@ -50,15 +47,22 @@ export default async function mdast2docx(mdast, log = console) {
50
47
 
51
48
  const children = await all(ctx, mdast);
52
49
 
53
- // read styles from template.docx. this seems to be the most reliable
54
- // const templateDoc = await readFile(path.resolve(__dirname, 'template.docx'));
55
- // const zip = await openArrayBuffer(templateDoc);
56
- // const styleXML = await zip.read('word/styles.xml', 'utf-8');
57
- const styleXML = await readFile(path.resolve(__dirname, 'template', 'word', 'styles.xml'), 'utf-8');
50
+ if (!stylesXML) {
51
+ // read styles from template.docx. this seems to be the most reliable
52
+ // const templateDoc = await readFile(path.resolve(__dirname, 'template.docx'));
53
+ // const zip = await openArrayBuffer(templateDoc);
54
+ // const stylesXML = await zip.read('word/styles.xml', 'utf-8');
55
+
56
+ // eslint-disable-next-line no-underscore-dangle
57
+ const __dirname = url.fileURLToPath ? path.dirname(url.fileURLToPath(import.meta.url)) : './';
58
+
59
+ // eslint-disable-next-line no-param-reassign
60
+ stylesXML = await readFile(path.resolve(__dirname, 'template', 'word', 'styles.xml'), 'utf-8');
61
+ }
58
62
 
59
63
  const doc = new Document({
60
64
  numbering,
61
- externalStyles: styleXML,
65
+ externalStyles: stylesXML,
62
66
  sections: [{
63
67
  children,
64
68
  }],