@open-egretta/lexical-export-docx 0.0.1 → 0.0.2
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 +1 -0
- package/dist/index.cjs +46 -17
- package/dist/index.js +34 -5
- package/package.json +7 -2
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -61,51 +61,80 @@ async function buildDocx(elements) {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
// src/nodes/paragraph.ts
|
|
64
|
-
var
|
|
64
|
+
var import_docx4 = require("docx");
|
|
65
65
|
|
|
66
66
|
// src/nodes/text.ts
|
|
67
67
|
var import_docx2 = require("docx");
|
|
68
|
-
function convertText(node) {
|
|
68
|
+
function convertText(node, style) {
|
|
69
69
|
return new import_docx2.TextRun({
|
|
70
70
|
text: node.text,
|
|
71
71
|
bold: (node.format & 1) !== 0,
|
|
72
72
|
italics: (node.format & 2) !== 0,
|
|
73
|
-
underline: (node.format & 8) !== 0 ? {} : void 0
|
|
73
|
+
underline: (node.format & 8) !== 0 ? {} : void 0,
|
|
74
|
+
style
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// src/nodes/link.ts
|
|
79
|
+
var import_docx3 = require("docx");
|
|
80
|
+
function convertLink(node) {
|
|
81
|
+
const runs = node.children.filter((c) => c.type === "text").map((c) => convertText(c, "Hyperlink"));
|
|
82
|
+
return new import_docx3.ExternalHyperlink({
|
|
83
|
+
link: node.url,
|
|
84
|
+
children: runs
|
|
74
85
|
});
|
|
75
86
|
}
|
|
76
87
|
|
|
77
88
|
// src/nodes/paragraph.ts
|
|
78
89
|
function convertParagraph(node) {
|
|
79
|
-
const runs = node.children.
|
|
80
|
-
|
|
90
|
+
const runs = node.children.flatMap((child) => {
|
|
91
|
+
if (child.type === "text")
|
|
92
|
+
return [convertText(child)];
|
|
93
|
+
if (child.type === "link")
|
|
94
|
+
return [convertLink(child)];
|
|
95
|
+
return [];
|
|
96
|
+
});
|
|
97
|
+
return new import_docx4.Paragraph({ children: runs });
|
|
81
98
|
}
|
|
82
99
|
|
|
83
100
|
// src/nodes/heading.ts
|
|
84
|
-
var
|
|
101
|
+
var import_docx5 = require("docx");
|
|
85
102
|
var HEADING_MAP = {
|
|
86
|
-
h1:
|
|
87
|
-
h2:
|
|
88
|
-
h3:
|
|
89
|
-
h4:
|
|
90
|
-
h5:
|
|
91
|
-
h6:
|
|
103
|
+
h1: import_docx5.HeadingLevel.HEADING_1,
|
|
104
|
+
h2: import_docx5.HeadingLevel.HEADING_2,
|
|
105
|
+
h3: import_docx5.HeadingLevel.HEADING_3,
|
|
106
|
+
h4: import_docx5.HeadingLevel.HEADING_4,
|
|
107
|
+
h5: import_docx5.HeadingLevel.HEADING_5,
|
|
108
|
+
h6: import_docx5.HeadingLevel.HEADING_6
|
|
92
109
|
};
|
|
93
110
|
function convertHeading(node) {
|
|
94
|
-
const runs = node.children.
|
|
95
|
-
|
|
111
|
+
const runs = node.children.flatMap((child) => {
|
|
112
|
+
if (child.type === "text")
|
|
113
|
+
return [convertText(child)];
|
|
114
|
+
if (child.type === "link")
|
|
115
|
+
return [convertLink(child)];
|
|
116
|
+
return [];
|
|
117
|
+
});
|
|
118
|
+
return new import_docx5.Paragraph({
|
|
96
119
|
heading: HEADING_MAP[node.tag],
|
|
97
120
|
children: runs
|
|
98
121
|
});
|
|
99
122
|
}
|
|
100
123
|
|
|
101
124
|
// src/nodes/list.ts
|
|
102
|
-
var
|
|
125
|
+
var import_docx6 = require("docx");
|
|
103
126
|
function convertList(node) {
|
|
104
127
|
return node.children.filter(
|
|
105
128
|
(child) => child.type === "listitem"
|
|
106
129
|
).map((item) => {
|
|
107
|
-
const runs = item.children.
|
|
108
|
-
|
|
130
|
+
const runs = item.children.flatMap((child) => {
|
|
131
|
+
if (child.type === "text")
|
|
132
|
+
return [convertText(child)];
|
|
133
|
+
if (child.type === "link")
|
|
134
|
+
return [convertLink(child)];
|
|
135
|
+
return [];
|
|
136
|
+
});
|
|
137
|
+
return new import_docx6.Paragraph({
|
|
109
138
|
bullet: node.listType === "bullet" ? { level: item.indent } : void 0,
|
|
110
139
|
numbering: node.listType === "number" ? { reference: "default-numbering", level: item.indent } : void 0,
|
|
111
140
|
children: runs
|
package/dist/index.js
CHANGED
|
@@ -38,18 +38,35 @@ import { Paragraph as Paragraph2 } from "docx";
|
|
|
38
38
|
|
|
39
39
|
// src/nodes/text.ts
|
|
40
40
|
import { TextRun } from "docx";
|
|
41
|
-
function convertText(node) {
|
|
41
|
+
function convertText(node, style) {
|
|
42
42
|
return new TextRun({
|
|
43
43
|
text: node.text,
|
|
44
44
|
bold: (node.format & 1) !== 0,
|
|
45
45
|
italics: (node.format & 2) !== 0,
|
|
46
|
-
underline: (node.format & 8) !== 0 ? {} : void 0
|
|
46
|
+
underline: (node.format & 8) !== 0 ? {} : void 0,
|
|
47
|
+
style
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/nodes/link.ts
|
|
52
|
+
import { ExternalHyperlink } from "docx";
|
|
53
|
+
function convertLink(node) {
|
|
54
|
+
const runs = node.children.filter((c) => c.type === "text").map((c) => convertText(c, "Hyperlink"));
|
|
55
|
+
return new ExternalHyperlink({
|
|
56
|
+
link: node.url,
|
|
57
|
+
children: runs
|
|
47
58
|
});
|
|
48
59
|
}
|
|
49
60
|
|
|
50
61
|
// src/nodes/paragraph.ts
|
|
51
62
|
function convertParagraph(node) {
|
|
52
|
-
const runs = node.children.
|
|
63
|
+
const runs = node.children.flatMap((child) => {
|
|
64
|
+
if (child.type === "text")
|
|
65
|
+
return [convertText(child)];
|
|
66
|
+
if (child.type === "link")
|
|
67
|
+
return [convertLink(child)];
|
|
68
|
+
return [];
|
|
69
|
+
});
|
|
53
70
|
return new Paragraph2({ children: runs });
|
|
54
71
|
}
|
|
55
72
|
|
|
@@ -64,7 +81,13 @@ var HEADING_MAP = {
|
|
|
64
81
|
h6: HeadingLevel.HEADING_6
|
|
65
82
|
};
|
|
66
83
|
function convertHeading(node) {
|
|
67
|
-
const runs = node.children.
|
|
84
|
+
const runs = node.children.flatMap((child) => {
|
|
85
|
+
if (child.type === "text")
|
|
86
|
+
return [convertText(child)];
|
|
87
|
+
if (child.type === "link")
|
|
88
|
+
return [convertLink(child)];
|
|
89
|
+
return [];
|
|
90
|
+
});
|
|
68
91
|
return new Paragraph3({
|
|
69
92
|
heading: HEADING_MAP[node.tag],
|
|
70
93
|
children: runs
|
|
@@ -77,7 +100,13 @@ function convertList(node) {
|
|
|
77
100
|
return node.children.filter(
|
|
78
101
|
(child) => child.type === "listitem"
|
|
79
102
|
).map((item) => {
|
|
80
|
-
const runs = item.children.
|
|
103
|
+
const runs = item.children.flatMap((child) => {
|
|
104
|
+
if (child.type === "text")
|
|
105
|
+
return [convertText(child)];
|
|
106
|
+
if (child.type === "link")
|
|
107
|
+
return [convertLink(child)];
|
|
108
|
+
return [];
|
|
109
|
+
});
|
|
81
110
|
return new Paragraph4({
|
|
82
111
|
bullet: node.listType === "bullet" ? { level: item.indent } : void 0,
|
|
83
112
|
numbering: node.listType === "number" ? { reference: "default-numbering", level: item.indent } : void 0,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-egretta/lexical-export-docx",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Export Lexical editor content to .docx format",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "",
|
|
@@ -15,7 +15,11 @@
|
|
|
15
15
|
"types": "./dist/index.d.ts"
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
|
-
"files": [
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
19
23
|
"keywords": [
|
|
20
24
|
"lexical",
|
|
21
25
|
"editor",
|
|
@@ -38,6 +42,7 @@
|
|
|
38
42
|
"lexical": ">=0.41.0"
|
|
39
43
|
},
|
|
40
44
|
"devDependencies": {
|
|
45
|
+
"@lexical/link": "^0.41.0",
|
|
41
46
|
"@lexical/list": "^0.41.0",
|
|
42
47
|
"@lexical/rich-text": "^0.41.0",
|
|
43
48
|
"lexical": "^0.41.0",
|