remark-docx 0.0.2 → 0.0.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/README.md +11 -10
- package/lib/index.d.ts +0 -1
- package/lib/index.js +11 -8
- package/lib/index.mjs +11 -3
- package/lib/transformer.d.ts +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,16 +27,16 @@ npm install remark-docx
|
|
|
27
27
|
```javascript
|
|
28
28
|
import { unified } from "unified";
|
|
29
29
|
import markdown from "remark-parse";
|
|
30
|
-
import docx
|
|
30
|
+
import docx from "remark-docx";
|
|
31
31
|
import { saveAs } from "file-saver";
|
|
32
32
|
|
|
33
|
-
const processor = unified().use(markdown).use(docx);
|
|
33
|
+
const processor = unified().use(markdown).use(docx, { output: "blob" });
|
|
34
34
|
|
|
35
35
|
const text = "# hello world";
|
|
36
36
|
|
|
37
37
|
(async () => {
|
|
38
38
|
const doc = await processor.process(text);
|
|
39
|
-
const blob = await
|
|
39
|
+
const blob = await doc.result;
|
|
40
40
|
saveAs(blob, "example.docx");
|
|
41
41
|
})();
|
|
42
42
|
```
|
|
@@ -46,23 +46,24 @@ const text = "# hello world";
|
|
|
46
46
|
```javascript
|
|
47
47
|
import { unified } from "unified";
|
|
48
48
|
import markdown from "remark-parse";
|
|
49
|
-
import docx
|
|
49
|
+
import docx from "remark-docx";
|
|
50
50
|
import * as fs from "fs";
|
|
51
51
|
|
|
52
|
-
const processor = unified().use(markdown).use(docx);
|
|
52
|
+
const processor = unified().use(markdown).use(docx, { output: "buffer" });
|
|
53
53
|
|
|
54
54
|
const text = "# hello world";
|
|
55
55
|
|
|
56
56
|
(async () => {
|
|
57
57
|
const doc = await processor.process(text);
|
|
58
|
-
const buffer = await
|
|
58
|
+
const buffer = await doc.result;
|
|
59
59
|
fs.writeFileSync("example.docx", buffer);
|
|
60
60
|
})();
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
## Options
|
|
64
64
|
|
|
65
|
-
| Key | Default | Type
|
|
66
|
-
| ------------- | --------- |
|
|
67
|
-
|
|
|
68
|
-
|
|
|
65
|
+
| Key | Default | Type | Description |
|
|
66
|
+
| ------------- | --------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
67
|
+
| output | "buffer" | `"buffer"` `"blob"` `"raw"` | Set output type of `VFile.result`. `buffer` is `Promise<ArrayBuffer>`. `blob` is `Promise<Blob>`. `raw` is internal data for testing. |
|
|
68
|
+
| docProperties | undefined | object | Override properties of document. |
|
|
69
|
+
| imageResolver | undefined | ImageResolver | **You must set** if your markdown includes images. See example for [browser](https://github.com/inokawa/remark-docx/blob/main/stories/playground.stories.tsx) and [Node.js](https://github.com/inokawa/remark-docx/blob/main/src/index.spec.ts). |
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var unistUtilVisit = require('unist-util-visit');
|
|
6
4
|
var docx = require('docx');
|
|
7
5
|
|
|
@@ -158,7 +156,16 @@ var error = function (message) {
|
|
|
158
156
|
throw new Error(message);
|
|
159
157
|
};
|
|
160
158
|
function mdastToDocx(node, opts, images) {
|
|
161
|
-
|
|
159
|
+
var _a;
|
|
160
|
+
var doc = buildDocxRoot(node, opts, images);
|
|
161
|
+
switch ((_a = opts.output) !== null && _a !== void 0 ? _a : "buffer") {
|
|
162
|
+
case "buffer":
|
|
163
|
+
return docx.Packer.toBuffer(doc);
|
|
164
|
+
case "blob":
|
|
165
|
+
return docx.Packer.toBlob(doc);
|
|
166
|
+
case "raw":
|
|
167
|
+
return doc;
|
|
168
|
+
}
|
|
162
169
|
}
|
|
163
170
|
function buildDocxRoot(root, opts, images) {
|
|
164
171
|
var ctx = { deco: {}, images: images };
|
|
@@ -484,8 +491,4 @@ var plugin = function (opts) {
|
|
|
484
491
|
}); };
|
|
485
492
|
};
|
|
486
493
|
|
|
487
|
-
|
|
488
|
-
enumerable: true,
|
|
489
|
-
get: function () { return docx.Packer; }
|
|
490
|
-
});
|
|
491
|
-
exports["default"] = plugin;
|
|
494
|
+
module.exports = plugin;
|
package/lib/index.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { visit } from 'unist-util-visit';
|
|
2
2
|
import * as docx from 'docx';
|
|
3
|
-
import { convertInchesToTwip } from 'docx';
|
|
4
|
-
export { Packer } from 'docx';
|
|
3
|
+
import { convertInchesToTwip, Packer } from 'docx';
|
|
5
4
|
|
|
6
5
|
/*! *****************************************************************************
|
|
7
6
|
Copyright (c) Microsoft Corporation.
|
|
@@ -136,7 +135,16 @@ var error = function (message) {
|
|
|
136
135
|
throw new Error(message);
|
|
137
136
|
};
|
|
138
137
|
function mdastToDocx(node, opts, images) {
|
|
139
|
-
|
|
138
|
+
var _a;
|
|
139
|
+
var doc = buildDocxRoot(node, opts, images);
|
|
140
|
+
switch ((_a = opts.output) !== null && _a !== void 0 ? _a : "buffer") {
|
|
141
|
+
case "buffer":
|
|
142
|
+
return Packer.toBuffer(doc);
|
|
143
|
+
case "blob":
|
|
144
|
+
return Packer.toBlob(doc);
|
|
145
|
+
case "raw":
|
|
146
|
+
return doc;
|
|
147
|
+
}
|
|
140
148
|
}
|
|
141
149
|
function buildDocxRoot(root, opts, images) {
|
|
142
150
|
var ctx = { deco: {}, images: images };
|
package/lib/transformer.d.ts
CHANGED
|
@@ -11,7 +11,8 @@ export declare type ImageData = {
|
|
|
11
11
|
};
|
|
12
12
|
export declare type ImageResolver = (url: string) => Promise<ImageData> | ImageData;
|
|
13
13
|
export declare type Opts = {
|
|
14
|
+
output?: "buffer" | "blob" | "raw";
|
|
14
15
|
docProperties?: Omit<IPropertiesOptions, "sections" | "numbering">;
|
|
15
16
|
imageResolver?: ImageResolver;
|
|
16
17
|
};
|
|
17
|
-
export declare function mdastToDocx(node: mdast.Root, opts: Opts, images: ImageDataMap): docx.File;
|
|
18
|
+
export declare function mdastToDocx(node: mdast.Root, opts: Opts, images: ImageDataMap): Promise<any> | docx.File;
|