remark-docx 0.2.0 → 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
@@ -2,7 +2,11 @@
2
2
 
3
3
  ![npm](https://img.shields.io/npm/v/remark-docx) ![npm](https://img.shields.io/npm/dw/remark-docx) ![check](https://github.com/inokawa/remark-docx/workflows/check/badge.svg) ![demo](https://github.com/inokawa/remark-docx/workflows/demo/badge.svg)
4
4
 
5
- [remark](https://github.com/remarkjs/remark) plugin to compile markdown to docx (Microsoft Word, Office Open XML).
5
+ > [remark](https://github.com/remarkjs/remark) plugin to compile markdown to docx (Microsoft Word, Office Open XML).
6
+
7
+ - Uses [docx](https://github.com/dolanmiu/docx) for compilation.
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.
6
10
 
7
11
  ### 🚧 WIP 🚧
8
12
 
@@ -19,25 +23,21 @@ If you have some feature requests or improvements, please create a [issue](https
19
23
  - [x] table
20
24
  - [x] tableRow
21
25
  - [x] tableCell
22
- - [ ] html
23
- - [ ] code
24
- - [ ] yaml
25
- - [ ] toml
26
26
  - [x] definition
27
27
  - [x] footnoteDefinition
28
28
  - [x] text
29
29
  - [x] emphasis
30
30
  - [x] strong
31
31
  - [x] delete
32
- - [ ] inlineCode
33
32
  - [x] break
34
- - [x] link
35
- - [x] image
36
- - [x] linkReference
37
- - [x] imageReference
38
- - [x] footnote
39
- - [x] footnoteReference
40
- - [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)
41
41
 
42
42
  ## Demo
43
43
 
@@ -49,7 +49,7 @@ https://inokawa.github.io/remark-docx/
49
49
  npm install remark-docx
50
50
  ```
51
51
 
52
- ## Usage
52
+ ## Getting started
53
53
 
54
54
  ### Browser
55
55
 
@@ -59,14 +59,14 @@ import markdown from "remark-parse";
59
59
  import docx from "remark-docx";
60
60
  import { saveAs } from "file-saver";
61
61
 
62
- const processor = unified().use(markdown).use(docx, { output: "blob" });
62
+ const processor = unified().use(markdown).use(docx);
63
63
 
64
64
  const text = "# hello world";
65
65
 
66
66
  (async () => {
67
67
  const doc = await processor.process(text);
68
- const blob = await doc.result;
69
- saveAs(blob, "example.docx");
68
+ const arrayBuffer = await doc.result;
69
+ saveAs(new Blob([arrayBuffer]), "example.docx");
70
70
  })();
71
71
  ```
72
72
 
@@ -78,17 +78,60 @@ import markdown from "remark-parse";
78
78
  import docx from "remark-docx";
79
79
  import * as fs from "fs";
80
80
 
81
- const processor = unified().use(markdown).use(docx, { output: "buffer" });
81
+ const processor = unified().use(markdown).use(docx);
82
82
 
83
83
  const text = "# hello world";
84
84
 
85
85
  (async () => {
86
86
  const doc = await processor.process(text);
87
- const buffer = await doc.result;
88
- fs.writeFileSync("example.docx", buffer);
87
+ const arrayBuffer = await doc.result;
88
+ fs.writeFileSync("example.docx", Buffer.from(arrayBuffer));
89
89
  })();
90
90
  ```
91
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
+
92
135
  ## Documentation
93
136
 
94
137
  - [API reference](./docs/API.md)