remark-docx 0.2.1 → 0.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/README.md CHANGED
@@ -6,6 +6,7 @@
6
6
 
7
7
  - Uses [docx](https://github.com/dolanmiu/docx) for compilation.
8
8
  - Works in any environment (e.g. browser, Node.js).
9
+ - You can customize [mdast](https://github.com/syntax-tree/mdast) to Word transformation with plugin system.
9
10
 
10
11
  ### 🚧 WIP 🚧
11
12
 
@@ -22,25 +23,21 @@ If you have some feature requests or improvements, please create a [issue](https
22
23
  - [x] table
23
24
  - [x] tableRow
24
25
  - [x] tableCell
25
- - [ ] html
26
- - [ ] code
27
- - [ ] yaml
28
- - [ ] toml
29
26
  - [x] definition
30
27
  - [x] footnoteDefinition
31
28
  - [x] text
32
29
  - [x] emphasis
33
30
  - [x] strong
34
31
  - [x] delete
35
- - [ ] inlineCode
36
32
  - [x] break
37
- - [x] link
38
- - [x] image
39
- - [x] linkReference
40
- - [x] imageReference
41
- - [x] footnote
42
- - [x] footnoteReference
43
- - [x] LaTeX support with math and inlineMath ([remark-math](https://github.com/remarkjs/remark-math) is required)
33
+ - [x] link / linkReference
34
+ - [x] image / imageReference ([remark-docx/plugins/image](#image) is required)
35
+ - [x] footnote / footnoteReference
36
+ - [ ] html
37
+ - [ ] yaml
38
+ - [ ] toml
39
+ - [ ] code / inlineCode
40
+ - [x] math / inlineMath ([remark-math](https://github.com/remarkjs/remark-math) and [remark-docx/plugins/math](#latex) are required)
44
41
 
45
42
  ## Demo
46
43
 
@@ -52,7 +49,7 @@ https://inokawa.github.io/remark-docx/
52
49
  npm install remark-docx
53
50
  ```
54
51
 
55
- ## Usage
52
+ ## Getting started
56
53
 
57
54
  ### Browser
58
55
 
@@ -62,14 +59,14 @@ import markdown from "remark-parse";
62
59
  import docx from "remark-docx";
63
60
  import { saveAs } from "file-saver";
64
61
 
65
- const processor = unified().use(markdown).use(docx, { output: "blob" });
62
+ const processor = unified().use(markdown).use(docx);
66
63
 
67
64
  const text = "# hello world";
68
65
 
69
66
  (async () => {
70
67
  const doc = await processor.process(text);
71
- const blob = await doc.result;
72
- saveAs(blob, "example.docx");
68
+ const arrayBuffer = await doc.result;
69
+ saveAs(new Blob([arrayBuffer]), "example.docx");
73
70
  })();
74
71
  ```
75
72
 
@@ -81,17 +78,60 @@ import markdown from "remark-parse";
81
78
  import docx from "remark-docx";
82
79
  import * as fs from "fs";
83
80
 
84
- const processor = unified().use(markdown).use(docx, { output: "buffer" });
81
+ const processor = unified().use(markdown).use(docx);
85
82
 
86
83
  const text = "# hello world";
87
84
 
88
85
  (async () => {
89
86
  const doc = await processor.process(text);
90
- const buffer = await doc.result;
91
- fs.writeFileSync("example.docx", buffer);
87
+ const arrayBuffer = await doc.result;
88
+ fs.writeFileSync("example.docx", Buffer.from(arrayBuffer));
92
89
  })();
93
90
  ```
94
91
 
92
+ ## With plugins
93
+
94
+ ### Image
95
+
96
+ #### Browser
97
+
98
+ ```javascript
99
+ import { unified } from "unified";
100
+ import markdown from "remark-parse";
101
+ import docx from "remark-docx";
102
+ import { browserImagePlugin } from "remark-docx/plugins/image";
103
+
104
+ const processor = unified()
105
+ .use(markdown)
106
+ .use(docx, { plugins: [browserImagePlugin()] });
107
+ ```
108
+
109
+ #### Node.js
110
+
111
+ ```javascript
112
+ import { unified } from "unified";
113
+ import markdown from "remark-parse";
114
+ import docx from "remark-docx";
115
+ import { nodeImagePlugin } from "remark-docx/plugins/image";
116
+
117
+ const processor = unified()
118
+ .use(markdown)
119
+ .use(docx, { plugins: [nodeImagePlugin()] });
120
+ ```
121
+
122
+ ### LaTeX
123
+
124
+ ```javascript
125
+ import { unified } from "unified";
126
+ import markdown from "remark-parse";
127
+ import docx from "remark-docx";
128
+ import { latexPlugin } from "remark-docx/plugins/math";
129
+
130
+ const processor = unified()
131
+ .use(markdown)
132
+ .use(docx, { plugins: [latexPlugin()] });
133
+ ```
134
+
95
135
  ## Documentation
96
136
 
97
137
  - [API reference](./docs/API.md)