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 +63 -20
- package/lib/index.cjs +45 -465
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +46 -466
- package/lib/index.js.map +1 -1
- package/lib/mdast-to-docx.d.ts +6 -19
- package/lib/mdast.d.ts +2 -0
- package/lib/plugin.d.ts +8 -2
- package/lib/plugins/image/index.cjs +119 -0
- package/lib/plugins/image/index.cjs.map +1 -0
- package/lib/plugins/image/index.d.ts +17 -0
- package/lib/plugins/image/index.js +116 -0
- package/lib/plugins/image/index.js.map +1 -0
- package/lib/plugins/math/index.cjs +376 -0
- package/lib/plugins/math/index.cjs.map +1 -0
- package/lib/plugins/math/index.d.ts +5 -0
- package/lib/plugins/math/index.js +374 -0
- package/lib/plugins/math/index.js.map +1 -0
- package/lib/plugins/types.d.ts +15 -0
- package/lib/types.d.ts +3 -0
- package/lib/utils-40yKzkXT.js +19 -0
- package/lib/utils-40yKzkXT.js.map +1 -0
- package/lib/utils-EYEfXxbh.js +22 -0
- package/lib/utils-EYEfXxbh.js.map +1 -0
- package/package.json +30 -22
- package/lib/models/mdast.d.ts +0 -21
- /package/lib/{latex.d.ts → plugins/math/parser.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
   
|
|
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]
|
|
37
|
-
- [
|
|
38
|
-
- [
|
|
39
|
-
- [
|
|
40
|
-
- [
|
|
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
|
-
##
|
|
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
|
|
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
|
|
69
|
-
saveAs(
|
|
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
|
|
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
|
|
88
|
-
fs.writeFileSync("example.docx",
|
|
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)
|