@adobe/helix-md2docx 1.2.3 → 1.3.3
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 +28 -0
- package/package.json +13 -12
- package/src/md2docx/index.d.ts +22 -0
- package/src/md2docx/index.js +2 -2
- package/src/mdast2docx/index.d.ts +2 -1
- package/src/mdast2docx/index.js +14 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
## [1.3.3](https://github.com/adobe/helix-md2docx/compare/v1.3.2...v1.3.3) (2022-02-04)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** update dependency @adobe/helix-fetch to v3.0.3 ([#21](https://github.com/adobe/helix-md2docx/issues/21)) ([9e6848a](https://github.com/adobe/helix-md2docx/commit/9e6848a99b88236e6e09ebc92ea126cca9d15820))
|
|
7
|
+
|
|
8
|
+
## [1.3.2](https://github.com/adobe/helix-md2docx/compare/v1.3.1...v1.3.2) (2022-02-04)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **deps:** update adobe fixes ([2f017a9](https://github.com/adobe/helix-md2docx/commit/2f017a9a2b607df988b04a2452b93c4caae631e2))
|
|
14
|
+
|
|
15
|
+
## [1.3.1](https://github.com/adobe/helix-md2docx/compare/v1.3.0...v1.3.1) (2022-02-03)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* **deps:** update dependency @adobe/helix-shared-process-queue to v1.1.1 ([#19](https://github.com/adobe/helix-md2docx/issues/19)) ([97db05e](https://github.com/adobe/helix-md2docx/commit/97db05e76cade37c2f5e37e210039d284d4ac094))
|
|
21
|
+
|
|
22
|
+
# [1.3.0](https://github.com/adobe/helix-md2docx/compare/v1.2.3...v1.3.0) (2022-02-02)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* allow to provide styles.xml ([e01c784](https://github.com/adobe/helix-md2docx/commit/e01c78458ab7270fd9924f32767df1f204689e5b))
|
|
28
|
+
|
|
1
29
|
## [1.2.3](https://github.com/adobe/helix-md2docx/compare/v1.2.2...v1.2.3) (2022-01-25)
|
|
2
30
|
|
|
3
31
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/helix-md2docx",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"description": "Helix Service that converts markdown to word documents",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/adobe/helix-md2docx#readme",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@adobe/helix-fetch": "3.0.
|
|
30
|
+
"@adobe/helix-fetch": "3.0.3",
|
|
31
31
|
"@adobe/helix-markdown-support": "3.1.2",
|
|
32
|
-
"@adobe/helix-shared-process-queue": "1.1.
|
|
33
|
-
"@adobe/helix-docx2md": "1.0.
|
|
32
|
+
"@adobe/helix-shared-process-queue": "1.1.1",
|
|
33
|
+
"@adobe/helix-docx2md": "1.0.7",
|
|
34
34
|
"docx": "7.3.0",
|
|
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.
|
|
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.
|
|
46
|
+
"@adobe/helix-mediahandler": "1.0.4",
|
|
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.
|
|
51
|
+
"chai": "4.3.6",
|
|
52
52
|
"codecov": "3.8.3",
|
|
53
|
-
"dotenv": "14.2
|
|
54
|
-
"eslint": "8.
|
|
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.
|
|
61
|
-
"mocha": "9.
|
|
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"
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
declare interface Logger {}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Converts the md to a word document (docx).
|
|
16
|
+
*
|
|
17
|
+
* @param {Node} md The md
|
|
18
|
+
* @param {Logger} [log] a console like logger
|
|
19
|
+
* @param {string} [stylesXML] The content of the styles.xml file of a Word template (to override provided default)
|
|
20
|
+
* @returns {Promise<Buffer>} the docx
|
|
21
|
+
*/
|
|
22
|
+
export default function md2docx(mdast: object, log: Logger, stylesXML: string): Promise<Buffer>;
|
package/src/md2docx/index.js
CHANGED
|
@@ -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
|
}
|
|
@@ -16,6 +16,7 @@ declare interface Logger {}
|
|
|
16
16
|
*
|
|
17
17
|
* @param {Node} mdast The mdast
|
|
18
18
|
* @param {Logger} [log] a console like logger
|
|
19
|
+
* @param {string} [stylesXML] The content of the styles.xml file of a Word template (to override provided default)
|
|
19
20
|
* @returns {Promise<Buffer>} the docx
|
|
20
21
|
*/
|
|
21
|
-
export default function mdast2docx(mdast: object, log: Logger): Promise<Buffer>;
|
|
22
|
+
export default function mdast2docx(mdast: object, log: Logger, stylesXML: string): Promise<Buffer>;
|
package/src/mdast2docx/index.js
CHANGED
|
@@ -24,10 +24,7 @@ import downloadImages from './mdast-download-images.js';
|
|
|
24
24
|
|
|
25
25
|
const { Document, Packer } = docx;
|
|
26
26
|
|
|
27
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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:
|
|
65
|
+
externalStyles: stylesXML,
|
|
62
66
|
sections: [{
|
|
63
67
|
children,
|
|
64
68
|
}],
|