@editkit/export 0.0.0-stage → 2.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ashikur
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,378 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ editorFromJSON: () => editorFromJSON,
24
+ editorToJSON: () => editorToJSON,
25
+ exportDocx: () => exportDocx,
26
+ exportPdfViaAdapter: () => exportPdfViaAdapter,
27
+ fromMarkdown: () => fromMarkdown,
28
+ normalizeWordHtml: () => normalizeWordHtml,
29
+ printPdf: () => printPdf,
30
+ toCleanHtml: () => toCleanHtml,
31
+ toEmailHtml: () => toEmailHtml,
32
+ toMarkdown: () => toMarkdown,
33
+ toPlainText: () => toPlainText
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+ function resolveWindow(options = {}) {
37
+ const candidate = options.window || globalThis.window;
38
+ if (!candidate) throw new Error("[editkit/export] A DOM window is required");
39
+ return candidate;
40
+ }
41
+ function parse(html, options = {}) {
42
+ const win = resolveWindow(options);
43
+ const safe = options.sanitize ? options.sanitize(html) : html;
44
+ const container = win.document.createElement("div");
45
+ container.innerHTML = safe;
46
+ return container;
47
+ }
48
+ function escapeMarkdown(text) {
49
+ return text.replace(/([\\`*_{}[\]()#+\-.!>])/g, "\\$1");
50
+ }
51
+ function escapeHtml(text) {
52
+ return text.replace(/[&<>"']/g, (char) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#039;" })[char] || char);
53
+ }
54
+ function inlineToMarkdown(node) {
55
+ if (node.nodeType === 3) return escapeMarkdown(node.textContent || "");
56
+ if (node.nodeType !== 1) return "";
57
+ const el = node;
58
+ const children = Array.from(el.childNodes).map(inlineToMarkdown).join("");
59
+ switch (el.tagName) {
60
+ case "STRONG":
61
+ case "B":
62
+ return `**${children}**`;
63
+ case "EM":
64
+ case "I":
65
+ return `*${children}*`;
66
+ case "S":
67
+ case "DEL":
68
+ case "STRIKE":
69
+ return `~~${children}~~`;
70
+ case "CODE":
71
+ return `\`${children}\``;
72
+ case "A":
73
+ return `[${children}](${el.getAttribute("href") || ""})`;
74
+ case "IMG":
75
+ return `![${el.getAttribute("alt") || ""}](${el.getAttribute("src") || ""})`;
76
+ case "BR":
77
+ return "\n";
78
+ default:
79
+ return children;
80
+ }
81
+ }
82
+ function tableToMarkdown(table) {
83
+ const rows = Array.from(table.querySelectorAll("tr")).map((row) => Array.from(row.querySelectorAll("th,td")).map((cell) => (cell.textContent || "").trim().replace(/\|/g, "\\|")));
84
+ if (!rows.length) return "";
85
+ const header = rows[0];
86
+ const divider = header.map(() => "---");
87
+ const body = rows.slice(1);
88
+ return [header, divider, ...body].map((row) => `| ${row.join(" | ")} |`).join("\n") + "\n\n";
89
+ }
90
+ function blockToMarkdown(node) {
91
+ if (node.nodeType === 3) {
92
+ const text = node.textContent || "";
93
+ return text.trim() ? `${text.trim()}
94
+
95
+ ` : "";
96
+ }
97
+ if (node.nodeType !== 1) return "";
98
+ const el = node;
99
+ const children = Array.from(el.childNodes).map(blockToMarkdown).join("").trimEnd();
100
+ switch (el.tagName) {
101
+ case "H1":
102
+ case "H2":
103
+ case "H3":
104
+ case "H4":
105
+ case "H5":
106
+ case "H6":
107
+ return `${"#".repeat(Number(el.tagName[1]))} ${children}
108
+
109
+ `;
110
+ case "P":
111
+ return `${inlineToMarkdown(el)}
112
+
113
+ `;
114
+ case "UL":
115
+ case "OL": {
116
+ const ordered = el.tagName === "OL";
117
+ return Array.from(el.children).map((item, index) => {
118
+ const task = item.classList.contains("editkit-task-item");
119
+ const marker = task ? item.classList.contains("editkit-task-done") ? "- [x] " : "- [ ] " : ordered ? `${index + 1}. ` : "- ";
120
+ return marker + inlineToMarkdown(item);
121
+ }).join("\n") + "\n\n";
122
+ }
123
+ case "BLOCKQUOTE":
124
+ return children.split("\n").map((line) => `> ${line}`).join("\n") + "\n\n";
125
+ case "PRE": {
126
+ const code = el.querySelector("code") || el;
127
+ const language = el.getAttribute("data-language") || "";
128
+ return `\`\`\`${language}
129
+ ${code.textContent || ""}
130
+ \`\`\`
131
+
132
+ `;
133
+ }
134
+ case "HR":
135
+ return "---\n\n";
136
+ case "TABLE":
137
+ return tableToMarkdown(el);
138
+ case "FIGURE":
139
+ case "DIV": {
140
+ if (el.classList.contains("editkit-image-figure")) {
141
+ const image = el.querySelector("img");
142
+ const caption = el.querySelector("figcaption");
143
+ return `![${caption?.textContent || image?.getAttribute("alt") || ""}](${image?.getAttribute("src") || ""})
144
+
145
+ `;
146
+ }
147
+ if (el.classList.contains("editkit-panel") || el.hasAttribute("data-editkit-block")) {
148
+ return `\`\`\`html
149
+ ${optionsFallback(el)}
150
+ \`\`\`
151
+
152
+ `;
153
+ }
154
+ return children + (children ? "\n\n" : "");
155
+ }
156
+ default:
157
+ return children + (children ? "\n\n" : "");
158
+ }
159
+ }
160
+ function optionsFallback(el) {
161
+ return el.outerHTML;
162
+ }
163
+ function toMarkdown(html, options = {}) {
164
+ const root = parse(html, options);
165
+ return Array.from(root.childNodes).map(blockToMarkdown).join("").replace(/\n{3,}/g, "\n\n").trim() + "\n";
166
+ }
167
+ function inlineMarkdown(text) {
168
+ let value = escapeHtml(text);
169
+ value = value.replace(/`([^`]+)`/g, "<code>$1</code>");
170
+ value = value.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>");
171
+ value = value.replace(/~~([^~]+)~~/g, "<s>$1</s>");
172
+ value = value.replace(/\*([^*]+)\*/g, "<em>$1</em>");
173
+ value = value.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_match, label, href) => `<a href="${escapeHtml(href)}">${label}</a>`);
174
+ value = value.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, (_match, alt, src) => `<img src="${escapeHtml(src)}" alt="${escapeHtml(alt)}">`);
175
+ return value;
176
+ }
177
+ function fromMarkdown(markdown, options = {}) {
178
+ const lines = markdown.replace(/\r/g, "").split("\n");
179
+ const output = [];
180
+ let listType = null;
181
+ let inCode = false;
182
+ let codeLanguage = "";
183
+ const closeList = () => {
184
+ if (listType) {
185
+ output.push(`</${listType}>`);
186
+ listType = null;
187
+ }
188
+ };
189
+ for (let index = 0; index < lines.length; index++) {
190
+ const line = lines[index];
191
+ if (line.startsWith("```")) {
192
+ if (inCode) {
193
+ output.push("</code></pre>");
194
+ inCode = false;
195
+ } else {
196
+ closeList();
197
+ codeLanguage = line.slice(3).trim();
198
+ output.push(`<pre${codeLanguage ? ` data-language="${escapeHtml(codeLanguage)}"` : ""}><code>`);
199
+ inCode = true;
200
+ }
201
+ continue;
202
+ }
203
+ if (inCode) {
204
+ output.push(escapeHtml(line));
205
+ continue;
206
+ }
207
+ const heading = /^(#{1,6})\s+(.*)$/.exec(line);
208
+ if (heading) {
209
+ closeList();
210
+ output.push(`<h${heading[1].length}>${inlineMarkdown(heading[2])}</h${heading[1].length}>`);
211
+ continue;
212
+ }
213
+ if (/^---+$/.test(line.trim())) {
214
+ closeList();
215
+ output.push("<hr>");
216
+ continue;
217
+ }
218
+ const task = /^-\s+\[([ xX])\]\s+(.*)$/.exec(line);
219
+ const bullet = /^-\s+(.*)$/.exec(line);
220
+ const ordered = /^\d+\.\s+(.*)$/.exec(line);
221
+ if (task || bullet || ordered) {
222
+ const wanted = task || bullet ? "ul" : "ol";
223
+ if (listType !== wanted) {
224
+ closeList();
225
+ output.push(`<${wanted}>`);
226
+ listType = wanted;
227
+ }
228
+ const content = task ? task[2] : (bullet || ordered)[1];
229
+ const className = task ? ` class="editkit-task-item${task[1] === " " ? "" : " editkit-task-done"}"` : "";
230
+ output.push(`<li${className}>${inlineMarkdown(content)}</li>`);
231
+ continue;
232
+ }
233
+ if (line.startsWith("> ")) {
234
+ closeList();
235
+ output.push(`<blockquote><p>${inlineMarkdown(line.slice(2))}</p></blockquote>`);
236
+ continue;
237
+ }
238
+ if (line.trim().startsWith("|")) {
239
+ closeList();
240
+ const rows = lines.slice(index).filter((row) => row.trim().startsWith("|"));
241
+ const cells = rows.map((row) => row.split("|").slice(1, -1).map((cell) => cell.trim()).filter((cell) => !/^---+$/.test(cell)));
242
+ output.push("<table><thead><tr>" + cells[0].map((cell) => `<th>${inlineMarkdown(cell)}</th>`).join("") + "</tr></thead><tbody>" + cells.slice(1).map((row) => `<tr>${row.map((cell) => `<td>${inlineMarkdown(cell)}</td>`).join("")}</tr>`).join("") + "</tbody></table>");
243
+ index += rows.length - 1;
244
+ continue;
245
+ }
246
+ if (!line.trim()) {
247
+ closeList();
248
+ continue;
249
+ }
250
+ closeList();
251
+ output.push(`<p>${inlineMarkdown(line)}</p>`);
252
+ }
253
+ closeList();
254
+ const html = output.join("");
255
+ return options.sanitize ? options.sanitize(html) : html;
256
+ }
257
+ function cleanNode(node, inlineStyles) {
258
+ if (node.hasAttribute("data-editkit-transient") || node.classList.contains("editkit-block-controls")) {
259
+ node.remove();
260
+ return;
261
+ }
262
+ for (const attr of Array.from(node.attributes)) {
263
+ if (attr.name.startsWith("data-editkit") || attr.name === "contenteditable" || attr.name === "spellcheck") node.removeAttribute(attr.name);
264
+ if (attr.name === "class" && (attr.value.includes("editkit-") || attr.value.includes("mso"))) node.removeAttribute("class");
265
+ if (attr.name === "style" && !inlineStyles) node.removeAttribute("style");
266
+ if (/^mso-|^aws-/i.test(attr.name)) node.removeAttribute(attr.name);
267
+ }
268
+ for (const child of Array.from(node.children)) cleanNode(child, inlineStyles);
269
+ }
270
+ function toCleanHtml(html, options = {}) {
271
+ const root = parse(html, options);
272
+ for (const child of Array.from(root.children)) cleanNode(child, Boolean(options.inlineStyles));
273
+ return root.innerHTML;
274
+ }
275
+ function toEmailHtml(html, options = {}) {
276
+ const root = parse(html, options);
277
+ for (const svg of Array.from(root.querySelectorAll("svg"))) svg.remove();
278
+ for (const columns of Array.from(root.querySelectorAll(".editkit-columns-container"))) {
279
+ const table = resolveWindow(options).document.createElement("table");
280
+ table.setAttribute("style", "width:100%;max-width:600px");
281
+ const row = table.insertRow();
282
+ for (const column of Array.from(columns.querySelectorAll(".editkit-column-body"))) {
283
+ const cell = row.insertCell();
284
+ cell.innerHTML = column.innerHTML;
285
+ }
286
+ columns.replaceWith(table);
287
+ }
288
+ for (const button of Array.from(root.querySelectorAll(".editkit-button-block"))) {
289
+ const table = resolveWindow(options).document.createElement("table");
290
+ const row = table.insertRow();
291
+ const cell = row.insertCell();
292
+ cell.innerHTML = button.innerHTML;
293
+ button.replaceWith(table);
294
+ }
295
+ for (const child of Array.from(root.children)) cleanNode(child, true);
296
+ return `<div style="max-width:600px;margin:0 auto;font-family:Arial,sans-serif">${root.innerHTML}</div>`;
297
+ }
298
+ function toPlainText(html, options = {}) {
299
+ const root = parse(html, options);
300
+ const parts = [];
301
+ const walk = (node) => {
302
+ if (node.nodeType === 3) return;
303
+ if (node.nodeType !== 1) return;
304
+ const el = node;
305
+ const own = Array.from(el.childNodes).filter((child) => child.nodeType === 3).map((child) => child.textContent || "").join("").trim();
306
+ if (el.tagName === "TABLE") {
307
+ parts.push(Array.from(el.querySelectorAll("tr")).map((row) => Array.from(row.querySelectorAll("th,td")).map((cell) => (cell.textContent || "").trim()).join(" ")).join("\n"));
308
+ return;
309
+ }
310
+ if (/^H[1-6]$/.test(el.tagName)) parts.push(`${"#".repeat(Number(el.tagName[1]))} ${own}`);
311
+ else if (el.tagName === "LI") parts.push(`- ${own}`);
312
+ else if (el.tagName === "P" && own) parts.push(own);
313
+ for (const child of Array.from(el.children)) walk(child);
314
+ };
315
+ for (const child of Array.from(root.childNodes)) walk(child);
316
+ return parts.filter(Boolean).join("\n\n");
317
+ }
318
+ function editorToJSON(editor) {
319
+ return editor.getJSON();
320
+ }
321
+ function editorFromJSON(editor, doc) {
322
+ editor.setJSON(doc);
323
+ }
324
+ function normalizeWordHtml(html, options = {}) {
325
+ const root = parse(html, options);
326
+ for (const element of Array.from(root.querySelectorAll("*"))) {
327
+ const style = element.getAttribute("style") || "";
328
+ if (/mso-/i.test(style)) {
329
+ const cleaned = style.split(";").filter((part) => !/mso-/i.test(part)).join(";");
330
+ if (cleaned) element.setAttribute("style", cleaned);
331
+ else element.removeAttribute("style");
332
+ }
333
+ const id = element.getAttribute("id") || "";
334
+ if (id.startsWith("docs-internal-guid") || element.hasAttribute("data-docs-internal-guid")) {
335
+ const parent = element.parentNode;
336
+ while (element.firstChild) parent.insertBefore(element.firstChild, element);
337
+ element.remove();
338
+ }
339
+ }
340
+ return root.innerHTML;
341
+ }
342
+ async function exportDocx(html, options = {}) {
343
+ const specifier = "docx";
344
+ const docxModule = await import(specifier).catch(() => {
345
+ throw new Error('[editkit/export] DOCX export requires the optional "docx" dependency');
346
+ });
347
+ const docx = docxModule;
348
+ const children = toPlainText(html, options).split("\n").filter(Boolean).map((line) => new docx.Paragraph(line));
349
+ const doc = new docx.Document({ sections: [{ children }] });
350
+ const blob = await docx.Packer.toBlob(doc);
351
+ return { blob, filename: options.filename || "editkit-document.docx" };
352
+ }
353
+ function printPdf(html, options = {}) {
354
+ const win = resolveWindow(options).open("", "_blank");
355
+ if (!win) throw new Error("[editkit/export] Pop-up blocked; allow pop-ups to print");
356
+ win.document.body.innerHTML = options.sanitize ? options.sanitize(html) : html;
357
+ win.focus();
358
+ win.print();
359
+ }
360
+ async function exportPdfViaAdapter(html, adapter, options = {}) {
361
+ const safe = options.sanitize ? options.sanitize(html) : html;
362
+ return { blob: await adapter(safe), filename: options.filename || "editkit-document.pdf" };
363
+ }
364
+ // Annotate the CommonJS export names for ESM import in node:
365
+ 0 && (module.exports = {
366
+ editorFromJSON,
367
+ editorToJSON,
368
+ exportDocx,
369
+ exportPdfViaAdapter,
370
+ fromMarkdown,
371
+ normalizeWordHtml,
372
+ printPdf,
373
+ toCleanHtml,
374
+ toEmailHtml,
375
+ toMarkdown,
376
+ toPlainText
377
+ });
378
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export interface ExportOptions {\n window?: Window;\n sanitize?: (html: string) => string;\n inlineStyles?: boolean;\n}\n\nexport interface ExportResult {\n blob: Blob;\n filename: string;\n}\n\ntype AnyNode = Node & { childNodes: NodeListOf<ChildNode> };\n\nfunction resolveWindow(options: ExportOptions = {}): Window {\n const candidate = options.window || (globalThis as { window?: Window }).window;\n if (!candidate) throw new Error('[editkit/export] A DOM window is required');\n return candidate;\n}\n\nfunction parse(html: string, options: ExportOptions = {}): HTMLElement {\n const win = resolveWindow(options);\n const safe = options.sanitize ? options.sanitize(html) : html;\n const container = win.document.createElement('div');\n container.innerHTML = safe;\n return container;\n}\n\nfunction escapeMarkdown(text: string): string {\n return text.replace(/([\\\\`*_{}[\\]()#+\\-.!>])/g, '\\\\$1');\n}\n\nfunction escapeHtml(text: string): string {\n return text.replace(/[&<>\"']/g, char => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '\"': '&quot;', \"'\": '&#039;' })[char] || char);\n}\n\nfunction inlineToMarkdown(node: Node): string {\n if (node.nodeType === 3) return escapeMarkdown(node.textContent || '');\n if (node.nodeType !== 1) return '';\n const el = node as HTMLElement;\n const children = Array.from(el.childNodes).map(inlineToMarkdown).join('');\n switch (el.tagName) {\n case 'STRONG': case 'B': return `**${children}**`;\n case 'EM': case 'I': return `*${children}*`;\n case 'S': case 'DEL': case 'STRIKE': return `~~${children}~~`;\n case 'CODE': return `\\`${children}\\``;\n case 'A': return `[${children}](${el.getAttribute('href') || ''})`;\n case 'IMG': return `![${el.getAttribute('alt') || ''}](${el.getAttribute('src') || ''})`;\n case 'BR': return '\\n';\n default: return children;\n }\n}\n\nfunction tableToMarkdown(table: HTMLTableElement): string {\n const rows = Array.from(table.querySelectorAll('tr')).map(row => Array.from(row.querySelectorAll('th,td')).map(cell => (cell.textContent || '').trim().replace(/\\|/g, '\\\\|')));\n if (!rows.length) return '';\n const header = rows[0];\n const divider = header.map(() => '---');\n const body = rows.slice(1);\n return [header, divider, ...body].map(row => `| ${row.join(' | ')} |`).join('\\n') + '\\n\\n';\n}\n\nfunction blockToMarkdown(node: Node): string {\n if (node.nodeType === 3) {\n const text = node.textContent || '';\n return text.trim() ? `${text.trim()}\\n\\n` : '';\n }\n if (node.nodeType !== 1) return '';\n const el = node as HTMLElement;\n const children = Array.from(el.childNodes).map(blockToMarkdown).join('').trimEnd();\n switch (el.tagName) {\n case 'H1': case 'H2': case 'H3': case 'H4': case 'H5': case 'H6':\n return `${'#'.repeat(Number(el.tagName[1]))} ${children}\\n\\n`;\n case 'P': return `${inlineToMarkdown(el)}\\n\\n`;\n case 'UL': case 'OL': {\n const ordered = el.tagName === 'OL';\n return Array.from(el.children).map((item, index) => {\n const task = item.classList.contains('editkit-task-item');\n const marker = task ? (item.classList.contains('editkit-task-done') ? '- [x] ' : '- [ ] ') : ordered ? `${index + 1}. ` : '- ';\n return marker + inlineToMarkdown(item);\n }).join('\\n') + '\\n\\n';\n }\n case 'BLOCKQUOTE': return children.split('\\n').map(line => `> ${line}`).join('\\n') + '\\n\\n';\n case 'PRE': {\n const code = el.querySelector('code') || el;\n const language = el.getAttribute('data-language') || '';\n return `\\`\\`\\`${language}\\n${code.textContent || ''}\\n\\`\\`\\`\\n\\n`;\n }\n case 'HR': return '---\\n\\n';\n case 'TABLE': return tableToMarkdown(el as HTMLTableElement);\n case 'FIGURE': case 'DIV': {\n if (el.classList.contains('editkit-image-figure')) {\n const image = el.querySelector('img');\n const caption = el.querySelector('figcaption');\n return `![${caption?.textContent || image?.getAttribute('alt') || ''}](${image?.getAttribute('src') || ''})\\n\\n`;\n }\n if (el.classList.contains('editkit-panel') || el.hasAttribute('data-editkit-block')) {\n return `\\`\\`\\`html\\n${optionsFallback(el)}\\n\\`\\`\\`\\n\\n`;\n }\n return children + (children ? '\\n\\n' : '');\n }\n default: return children + (children ? '\\n\\n' : '');\n }\n}\n\nfunction optionsFallback(el: HTMLElement): string {\n return el.outerHTML;\n}\n\nexport function toMarkdown(html: string, options: ExportOptions = {}): string {\n const root = parse(html, options);\n return Array.from(root.childNodes).map(blockToMarkdown).join('').replace(/\\n{3,}/g, '\\n\\n').trim() + '\\n';\n}\n\nfunction inlineMarkdown(text: string): string {\n let value = escapeHtml(text);\n value = value.replace(/`([^`]+)`/g, '<code>$1</code>');\n value = value.replace(/\\*\\*([^*]+)\\*\\*/g, '<strong>$1</strong>');\n value = value.replace(/~~([^~]+)~~/g, '<s>$1</s>');\n value = value.replace(/\\*([^*]+)\\*/g, '<em>$1</em>');\n value = value.replace(/\\[([^\\]]+)\\]\\(([^)]+)\\)/g, (_match, label, href) => `<a href=\"${escapeHtml(href)}\">${label}</a>`);\n value = value.replace(/!\\[([^\\]]*)\\]\\(([^)]+)\\)/g, (_match, alt, src) => `<img src=\"${escapeHtml(src)}\" alt=\"${escapeHtml(alt)}\">`);\n return value;\n}\n\nexport function fromMarkdown(markdown: string, options: ExportOptions = {}): string {\n const lines = markdown.replace(/\\r/g, '').split('\\n');\n const output: string[] = [];\n let listType: 'ul' | 'ol' | null = null;\n let inCode = false;\n let codeLanguage = '';\n\n const closeList = () => {\n if (listType) {\n output.push(`</${listType}>`);\n listType = null;\n }\n };\n\n for (let index = 0; index < lines.length; index++) {\n const line = lines[index];\n if (line.startsWith('```')) {\n if (inCode) {\n output.push('</code></pre>');\n inCode = false;\n } else {\n closeList();\n codeLanguage = line.slice(3).trim();\n output.push(`<pre${codeLanguage ? ` data-language=\"${escapeHtml(codeLanguage)}\"` : ''}><code>`);\n inCode = true;\n }\n continue;\n }\n if (inCode) {\n output.push(escapeHtml(line));\n continue;\n }\n const heading = /^(#{1,6})\\s+(.*)$/.exec(line);\n if (heading) {\n closeList();\n output.push(`<h${heading[1].length}>${inlineMarkdown(heading[2])}</h${heading[1].length}>`);\n continue;\n }\n if (/^---+$/.test(line.trim())) {\n closeList();\n output.push('<hr>');\n continue;\n }\n const task = /^-\\s+\\[([ xX])\\]\\s+(.*)$/.exec(line);\n const bullet = /^-\\s+(.*)$/.exec(line);\n const ordered = /^\\d+\\.\\s+(.*)$/.exec(line);\n if (task || bullet || ordered) {\n const wanted = task || bullet ? 'ul' : 'ol';\n if (listType !== wanted) {\n closeList();\n output.push(`<${wanted}>`);\n listType = wanted;\n }\n const content = task ? task[2] : (bullet || ordered)![1];\n const className = task ? ` class=\"editkit-task-item${task[1] === ' ' ? '' : ' editkit-task-done'}\"` : '';\n output.push(`<li${className}>${inlineMarkdown(content)}</li>`);\n continue;\n }\n if (line.startsWith('> ')) {\n closeList();\n output.push(`<blockquote><p>${inlineMarkdown(line.slice(2))}</p></blockquote>`);\n continue;\n }\n if (line.trim().startsWith('|')) {\n closeList();\n const rows = lines.slice(index).filter(row => row.trim().startsWith('|'));\n const cells = rows.map(row => row.split('|').slice(1, -1).map(cell => cell.trim()).filter(cell => !/^---+$/.test(cell)));\n output.push('<table><thead><tr>' + cells[0].map(cell => `<th>${inlineMarkdown(cell)}</th>`).join('') + '</tr></thead><tbody>' + cells.slice(1).map(row => `<tr>${row.map(cell => `<td>${inlineMarkdown(cell)}</td>`).join('')}</tr>`).join('') + '</tbody></table>');\n index += rows.length - 1;\n continue;\n }\n if (!line.trim()) {\n closeList();\n continue;\n }\n closeList();\n output.push(`<p>${inlineMarkdown(line)}</p>`);\n }\n closeList();\n const html = output.join('');\n return options.sanitize ? options.sanitize(html) : html;\n}\n\nfunction cleanNode(node: Element, inlineStyles: boolean): void {\n if (node.hasAttribute('data-editkit-transient') || node.classList.contains('editkit-block-controls')) {\n node.remove();\n return;\n }\n for (const attr of Array.from(node.attributes)) {\n if (attr.name.startsWith('data-editkit') || attr.name === 'contenteditable' || attr.name === 'spellcheck') node.removeAttribute(attr.name);\n if (attr.name === 'class' && (attr.value.includes('editkit-') || attr.value.includes('mso'))) node.removeAttribute('class');\n if (attr.name === 'style' && !inlineStyles) node.removeAttribute('style');\n if (/^mso-|^aws-/i.test(attr.name)) node.removeAttribute(attr.name);\n }\n for (const child of Array.from(node.children)) cleanNode(child, inlineStyles);\n}\n\nexport function toCleanHtml(html: string, options: ExportOptions = {}): string {\n const root = parse(html, options);\n for (const child of Array.from(root.children)) cleanNode(child, Boolean(options.inlineStyles));\n return root.innerHTML;\n}\n\nexport function toEmailHtml(html: string, options: ExportOptions = {}): string {\n const root = parse(html, options);\n for (const svg of Array.from(root.querySelectorAll('svg'))) svg.remove();\n for (const columns of Array.from(root.querySelectorAll('.editkit-columns-container'))) {\n const table = resolveWindow(options).document.createElement('table');\n table.setAttribute('style', 'width:100%;max-width:600px');\n const row = table.insertRow();\n for (const column of Array.from(columns.querySelectorAll('.editkit-column-body'))) {\n const cell = row.insertCell();\n cell.innerHTML = column.innerHTML;\n }\n columns.replaceWith(table);\n }\n for (const button of Array.from(root.querySelectorAll('.editkit-button-block'))) {\n const table = resolveWindow(options).document.createElement('table');\n const row = table.insertRow();\n const cell = row.insertCell();\n cell.innerHTML = button.innerHTML;\n button.replaceWith(table);\n }\n for (const child of Array.from(root.children)) cleanNode(child, true);\n return `<div style=\"max-width:600px;margin:0 auto;font-family:Arial,sans-serif\">${root.innerHTML}</div>`;\n}\n\nexport function toPlainText(html: string, options: ExportOptions = {}): string {\n const root = parse(html, options);\n const parts: string[] = [];\n const walk = (node: Node) => {\n if (node.nodeType === 3) return;\n if (node.nodeType !== 1) return;\n const el = node as HTMLElement;\n const own = Array.from(el.childNodes).filter(child => child.nodeType === 3).map(child => child.textContent || '').join('').trim();\n if (el.tagName === 'TABLE') {\n parts.push(Array.from(el.querySelectorAll('tr')).map(row => Array.from(row.querySelectorAll('th,td')).map(cell => (cell.textContent || '').trim()).join('\\t')).join('\\n'));\n return;\n }\n if (/^H[1-6]$/.test(el.tagName)) parts.push(`${'#'.repeat(Number(el.tagName[1]))} ${own}`);\n else if (el.tagName === 'LI') parts.push(`- ${own}`);\n else if (el.tagName === 'P' && own) parts.push(own);\n for (const child of Array.from(el.children)) walk(child);\n };\n for (const child of Array.from(root.childNodes)) walk(child);\n return parts.filter(Boolean).join('\\n\\n');\n}\n\nexport function editorToJSON(editor: { getJSON(): unknown }): unknown {\n return editor.getJSON();\n}\n\nexport function editorFromJSON(editor: { setJSON(doc: unknown): void }, doc: unknown): void {\n editor.setJSON(doc);\n}\n\nexport function normalizeWordHtml(html: string, options: ExportOptions = {}): string {\n const root = parse(html, options);\n for (const element of Array.from(root.querySelectorAll('*'))) {\n const style = element.getAttribute('style') || '';\n if (/mso-/i.test(style)) {\n const cleaned = style.split(';').filter(part => !/mso-/i.test(part)).join(';');\n if (cleaned) element.setAttribute('style', cleaned);\n else element.removeAttribute('style');\n }\n const id = element.getAttribute('id') || '';\n if (id.startsWith('docs-internal-guid') || element.hasAttribute('data-docs-internal-guid')) {\n const parent = element.parentNode!;\n while (element.firstChild) parent.insertBefore(element.firstChild, element);\n element.remove();\n }\n }\n return root.innerHTML;\n}\n\nexport async function exportDocx(html: string, options: ExportOptions & { filename?: string } = {}): Promise<ExportResult> {\n const specifier = 'docx';\n const docxModule = await import(specifier).catch(() => {\n throw new Error('[editkit/export] DOCX export requires the optional \"docx\" dependency');\n });\n const docx = docxModule as Record<string, any>;\n const children = toPlainText(html, options).split('\\n').filter(Boolean).map(line => new docx.Paragraph(line));\n const doc = new docx.Document({ sections: [{ children }] });\n const blob = await docx.Packer.toBlob(doc);\n return { blob, filename: options.filename || 'editkit-document.docx' };\n}\n\nexport function printPdf(html: string, options: ExportOptions = {}): void {\n const win = resolveWindow(options).open('', '_blank');\n if (!win) throw new Error('[editkit/export] Pop-up blocked; allow pop-ups to print');\n win.document.body.innerHTML = options.sanitize ? options.sanitize(html) : html;\n win.focus();\n win.print();\n}\n\nexport async function exportPdfViaAdapter(\n html: string,\n adapter: (safeHtml: string) => Promise<Blob>,\n options: ExportOptions & { filename?: string } = {},\n): Promise<ExportResult> {\n const safe = options.sanitize ? options.sanitize(html) : html;\n return { blob: await adapter(safe), filename: options.filename || 'editkit-document.pdf' };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA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EAAE,KAAK,IAAI,QAAQ;AACpD,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,yDAAyD;AACnF,MAAI,SAAS,KAAK,YAAY,QAAQ,WAAW,QAAQ,SAAS,IAAI,IAAI;AAC1E,MAAI,MAAM;AACV,MAAI,MAAM;AACZ;AAEA,eAAsB,oBACpB,MACA,SACA,UAAiD,CAAC,GAC3B;AACvB,QAAM,OAAO,QAAQ,WAAW,QAAQ,SAAS,IAAI,IAAI;AACzD,SAAO,EAAE,MAAM,MAAM,QAAQ,IAAI,GAAG,UAAU,QAAQ,YAAY,uBAAuB;AAC3F;","names":[]}
@@ -0,0 +1,30 @@
1
+ interface ExportOptions {
2
+ window?: Window;
3
+ sanitize?: (html: string) => string;
4
+ inlineStyles?: boolean;
5
+ }
6
+ interface ExportResult {
7
+ blob: Blob;
8
+ filename: string;
9
+ }
10
+ declare function toMarkdown(html: string, options?: ExportOptions): string;
11
+ declare function fromMarkdown(markdown: string, options?: ExportOptions): string;
12
+ declare function toCleanHtml(html: string, options?: ExportOptions): string;
13
+ declare function toEmailHtml(html: string, options?: ExportOptions): string;
14
+ declare function toPlainText(html: string, options?: ExportOptions): string;
15
+ declare function editorToJSON(editor: {
16
+ getJSON(): unknown;
17
+ }): unknown;
18
+ declare function editorFromJSON(editor: {
19
+ setJSON(doc: unknown): void;
20
+ }, doc: unknown): void;
21
+ declare function normalizeWordHtml(html: string, options?: ExportOptions): string;
22
+ declare function exportDocx(html: string, options?: ExportOptions & {
23
+ filename?: string;
24
+ }): Promise<ExportResult>;
25
+ declare function printPdf(html: string, options?: ExportOptions): void;
26
+ declare function exportPdfViaAdapter(html: string, adapter: (safeHtml: string) => Promise<Blob>, options?: ExportOptions & {
27
+ filename?: string;
28
+ }): Promise<ExportResult>;
29
+
30
+ export { type ExportOptions, type ExportResult, editorFromJSON, editorToJSON, exportDocx, exportPdfViaAdapter, fromMarkdown, normalizeWordHtml, printPdf, toCleanHtml, toEmailHtml, toMarkdown, toPlainText };
@@ -0,0 +1,30 @@
1
+ interface ExportOptions {
2
+ window?: Window;
3
+ sanitize?: (html: string) => string;
4
+ inlineStyles?: boolean;
5
+ }
6
+ interface ExportResult {
7
+ blob: Blob;
8
+ filename: string;
9
+ }
10
+ declare function toMarkdown(html: string, options?: ExportOptions): string;
11
+ declare function fromMarkdown(markdown: string, options?: ExportOptions): string;
12
+ declare function toCleanHtml(html: string, options?: ExportOptions): string;
13
+ declare function toEmailHtml(html: string, options?: ExportOptions): string;
14
+ declare function toPlainText(html: string, options?: ExportOptions): string;
15
+ declare function editorToJSON(editor: {
16
+ getJSON(): unknown;
17
+ }): unknown;
18
+ declare function editorFromJSON(editor: {
19
+ setJSON(doc: unknown): void;
20
+ }, doc: unknown): void;
21
+ declare function normalizeWordHtml(html: string, options?: ExportOptions): string;
22
+ declare function exportDocx(html: string, options?: ExportOptions & {
23
+ filename?: string;
24
+ }): Promise<ExportResult>;
25
+ declare function printPdf(html: string, options?: ExportOptions): void;
26
+ declare function exportPdfViaAdapter(html: string, adapter: (safeHtml: string) => Promise<Blob>, options?: ExportOptions & {
27
+ filename?: string;
28
+ }): Promise<ExportResult>;
29
+
30
+ export { type ExportOptions, type ExportResult, editorFromJSON, editorToJSON, exportDocx, exportPdfViaAdapter, fromMarkdown, normalizeWordHtml, printPdf, toCleanHtml, toEmailHtml, toMarkdown, toPlainText };
package/dist/index.js ADDED
@@ -0,0 +1,343 @@
1
+ // src/index.ts
2
+ function resolveWindow(options = {}) {
3
+ const candidate = options.window || globalThis.window;
4
+ if (!candidate) throw new Error("[editkit/export] A DOM window is required");
5
+ return candidate;
6
+ }
7
+ function parse(html, options = {}) {
8
+ const win = resolveWindow(options);
9
+ const safe = options.sanitize ? options.sanitize(html) : html;
10
+ const container = win.document.createElement("div");
11
+ container.innerHTML = safe;
12
+ return container;
13
+ }
14
+ function escapeMarkdown(text) {
15
+ return text.replace(/([\\`*_{}[\]()#+\-.!>])/g, "\\$1");
16
+ }
17
+ function escapeHtml(text) {
18
+ return text.replace(/[&<>"']/g, (char) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#039;" })[char] || char);
19
+ }
20
+ function inlineToMarkdown(node) {
21
+ if (node.nodeType === 3) return escapeMarkdown(node.textContent || "");
22
+ if (node.nodeType !== 1) return "";
23
+ const el = node;
24
+ const children = Array.from(el.childNodes).map(inlineToMarkdown).join("");
25
+ switch (el.tagName) {
26
+ case "STRONG":
27
+ case "B":
28
+ return `**${children}**`;
29
+ case "EM":
30
+ case "I":
31
+ return `*${children}*`;
32
+ case "S":
33
+ case "DEL":
34
+ case "STRIKE":
35
+ return `~~${children}~~`;
36
+ case "CODE":
37
+ return `\`${children}\``;
38
+ case "A":
39
+ return `[${children}](${el.getAttribute("href") || ""})`;
40
+ case "IMG":
41
+ return `![${el.getAttribute("alt") || ""}](${el.getAttribute("src") || ""})`;
42
+ case "BR":
43
+ return "\n";
44
+ default:
45
+ return children;
46
+ }
47
+ }
48
+ function tableToMarkdown(table) {
49
+ const rows = Array.from(table.querySelectorAll("tr")).map((row) => Array.from(row.querySelectorAll("th,td")).map((cell) => (cell.textContent || "").trim().replace(/\|/g, "\\|")));
50
+ if (!rows.length) return "";
51
+ const header = rows[0];
52
+ const divider = header.map(() => "---");
53
+ const body = rows.slice(1);
54
+ return [header, divider, ...body].map((row) => `| ${row.join(" | ")} |`).join("\n") + "\n\n";
55
+ }
56
+ function blockToMarkdown(node) {
57
+ if (node.nodeType === 3) {
58
+ const text = node.textContent || "";
59
+ return text.trim() ? `${text.trim()}
60
+
61
+ ` : "";
62
+ }
63
+ if (node.nodeType !== 1) return "";
64
+ const el = node;
65
+ const children = Array.from(el.childNodes).map(blockToMarkdown).join("").trimEnd();
66
+ switch (el.tagName) {
67
+ case "H1":
68
+ case "H2":
69
+ case "H3":
70
+ case "H4":
71
+ case "H5":
72
+ case "H6":
73
+ return `${"#".repeat(Number(el.tagName[1]))} ${children}
74
+
75
+ `;
76
+ case "P":
77
+ return `${inlineToMarkdown(el)}
78
+
79
+ `;
80
+ case "UL":
81
+ case "OL": {
82
+ const ordered = el.tagName === "OL";
83
+ return Array.from(el.children).map((item, index) => {
84
+ const task = item.classList.contains("editkit-task-item");
85
+ const marker = task ? item.classList.contains("editkit-task-done") ? "- [x] " : "- [ ] " : ordered ? `${index + 1}. ` : "- ";
86
+ return marker + inlineToMarkdown(item);
87
+ }).join("\n") + "\n\n";
88
+ }
89
+ case "BLOCKQUOTE":
90
+ return children.split("\n").map((line) => `> ${line}`).join("\n") + "\n\n";
91
+ case "PRE": {
92
+ const code = el.querySelector("code") || el;
93
+ const language = el.getAttribute("data-language") || "";
94
+ return `\`\`\`${language}
95
+ ${code.textContent || ""}
96
+ \`\`\`
97
+
98
+ `;
99
+ }
100
+ case "HR":
101
+ return "---\n\n";
102
+ case "TABLE":
103
+ return tableToMarkdown(el);
104
+ case "FIGURE":
105
+ case "DIV": {
106
+ if (el.classList.contains("editkit-image-figure")) {
107
+ const image = el.querySelector("img");
108
+ const caption = el.querySelector("figcaption");
109
+ return `![${caption?.textContent || image?.getAttribute("alt") || ""}](${image?.getAttribute("src") || ""})
110
+
111
+ `;
112
+ }
113
+ if (el.classList.contains("editkit-panel") || el.hasAttribute("data-editkit-block")) {
114
+ return `\`\`\`html
115
+ ${optionsFallback(el)}
116
+ \`\`\`
117
+
118
+ `;
119
+ }
120
+ return children + (children ? "\n\n" : "");
121
+ }
122
+ default:
123
+ return children + (children ? "\n\n" : "");
124
+ }
125
+ }
126
+ function optionsFallback(el) {
127
+ return el.outerHTML;
128
+ }
129
+ function toMarkdown(html, options = {}) {
130
+ const root = parse(html, options);
131
+ return Array.from(root.childNodes).map(blockToMarkdown).join("").replace(/\n{3,}/g, "\n\n").trim() + "\n";
132
+ }
133
+ function inlineMarkdown(text) {
134
+ let value = escapeHtml(text);
135
+ value = value.replace(/`([^`]+)`/g, "<code>$1</code>");
136
+ value = value.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>");
137
+ value = value.replace(/~~([^~]+)~~/g, "<s>$1</s>");
138
+ value = value.replace(/\*([^*]+)\*/g, "<em>$1</em>");
139
+ value = value.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_match, label, href) => `<a href="${escapeHtml(href)}">${label}</a>`);
140
+ value = value.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, (_match, alt, src) => `<img src="${escapeHtml(src)}" alt="${escapeHtml(alt)}">`);
141
+ return value;
142
+ }
143
+ function fromMarkdown(markdown, options = {}) {
144
+ const lines = markdown.replace(/\r/g, "").split("\n");
145
+ const output = [];
146
+ let listType = null;
147
+ let inCode = false;
148
+ let codeLanguage = "";
149
+ const closeList = () => {
150
+ if (listType) {
151
+ output.push(`</${listType}>`);
152
+ listType = null;
153
+ }
154
+ };
155
+ for (let index = 0; index < lines.length; index++) {
156
+ const line = lines[index];
157
+ if (line.startsWith("```")) {
158
+ if (inCode) {
159
+ output.push("</code></pre>");
160
+ inCode = false;
161
+ } else {
162
+ closeList();
163
+ codeLanguage = line.slice(3).trim();
164
+ output.push(`<pre${codeLanguage ? ` data-language="${escapeHtml(codeLanguage)}"` : ""}><code>`);
165
+ inCode = true;
166
+ }
167
+ continue;
168
+ }
169
+ if (inCode) {
170
+ output.push(escapeHtml(line));
171
+ continue;
172
+ }
173
+ const heading = /^(#{1,6})\s+(.*)$/.exec(line);
174
+ if (heading) {
175
+ closeList();
176
+ output.push(`<h${heading[1].length}>${inlineMarkdown(heading[2])}</h${heading[1].length}>`);
177
+ continue;
178
+ }
179
+ if (/^---+$/.test(line.trim())) {
180
+ closeList();
181
+ output.push("<hr>");
182
+ continue;
183
+ }
184
+ const task = /^-\s+\[([ xX])\]\s+(.*)$/.exec(line);
185
+ const bullet = /^-\s+(.*)$/.exec(line);
186
+ const ordered = /^\d+\.\s+(.*)$/.exec(line);
187
+ if (task || bullet || ordered) {
188
+ const wanted = task || bullet ? "ul" : "ol";
189
+ if (listType !== wanted) {
190
+ closeList();
191
+ output.push(`<${wanted}>`);
192
+ listType = wanted;
193
+ }
194
+ const content = task ? task[2] : (bullet || ordered)[1];
195
+ const className = task ? ` class="editkit-task-item${task[1] === " " ? "" : " editkit-task-done"}"` : "";
196
+ output.push(`<li${className}>${inlineMarkdown(content)}</li>`);
197
+ continue;
198
+ }
199
+ if (line.startsWith("> ")) {
200
+ closeList();
201
+ output.push(`<blockquote><p>${inlineMarkdown(line.slice(2))}</p></blockquote>`);
202
+ continue;
203
+ }
204
+ if (line.trim().startsWith("|")) {
205
+ closeList();
206
+ const rows = lines.slice(index).filter((row) => row.trim().startsWith("|"));
207
+ const cells = rows.map((row) => row.split("|").slice(1, -1).map((cell) => cell.trim()).filter((cell) => !/^---+$/.test(cell)));
208
+ output.push("<table><thead><tr>" + cells[0].map((cell) => `<th>${inlineMarkdown(cell)}</th>`).join("") + "</tr></thead><tbody>" + cells.slice(1).map((row) => `<tr>${row.map((cell) => `<td>${inlineMarkdown(cell)}</td>`).join("")}</tr>`).join("") + "</tbody></table>");
209
+ index += rows.length - 1;
210
+ continue;
211
+ }
212
+ if (!line.trim()) {
213
+ closeList();
214
+ continue;
215
+ }
216
+ closeList();
217
+ output.push(`<p>${inlineMarkdown(line)}</p>`);
218
+ }
219
+ closeList();
220
+ const html = output.join("");
221
+ return options.sanitize ? options.sanitize(html) : html;
222
+ }
223
+ function cleanNode(node, inlineStyles) {
224
+ if (node.hasAttribute("data-editkit-transient") || node.classList.contains("editkit-block-controls")) {
225
+ node.remove();
226
+ return;
227
+ }
228
+ for (const attr of Array.from(node.attributes)) {
229
+ if (attr.name.startsWith("data-editkit") || attr.name === "contenteditable" || attr.name === "spellcheck") node.removeAttribute(attr.name);
230
+ if (attr.name === "class" && (attr.value.includes("editkit-") || attr.value.includes("mso"))) node.removeAttribute("class");
231
+ if (attr.name === "style" && !inlineStyles) node.removeAttribute("style");
232
+ if (/^mso-|^aws-/i.test(attr.name)) node.removeAttribute(attr.name);
233
+ }
234
+ for (const child of Array.from(node.children)) cleanNode(child, inlineStyles);
235
+ }
236
+ function toCleanHtml(html, options = {}) {
237
+ const root = parse(html, options);
238
+ for (const child of Array.from(root.children)) cleanNode(child, Boolean(options.inlineStyles));
239
+ return root.innerHTML;
240
+ }
241
+ function toEmailHtml(html, options = {}) {
242
+ const root = parse(html, options);
243
+ for (const svg of Array.from(root.querySelectorAll("svg"))) svg.remove();
244
+ for (const columns of Array.from(root.querySelectorAll(".editkit-columns-container"))) {
245
+ const table = resolveWindow(options).document.createElement("table");
246
+ table.setAttribute("style", "width:100%;max-width:600px");
247
+ const row = table.insertRow();
248
+ for (const column of Array.from(columns.querySelectorAll(".editkit-column-body"))) {
249
+ const cell = row.insertCell();
250
+ cell.innerHTML = column.innerHTML;
251
+ }
252
+ columns.replaceWith(table);
253
+ }
254
+ for (const button of Array.from(root.querySelectorAll(".editkit-button-block"))) {
255
+ const table = resolveWindow(options).document.createElement("table");
256
+ const row = table.insertRow();
257
+ const cell = row.insertCell();
258
+ cell.innerHTML = button.innerHTML;
259
+ button.replaceWith(table);
260
+ }
261
+ for (const child of Array.from(root.children)) cleanNode(child, true);
262
+ return `<div style="max-width:600px;margin:0 auto;font-family:Arial,sans-serif">${root.innerHTML}</div>`;
263
+ }
264
+ function toPlainText(html, options = {}) {
265
+ const root = parse(html, options);
266
+ const parts = [];
267
+ const walk = (node) => {
268
+ if (node.nodeType === 3) return;
269
+ if (node.nodeType !== 1) return;
270
+ const el = node;
271
+ const own = Array.from(el.childNodes).filter((child) => child.nodeType === 3).map((child) => child.textContent || "").join("").trim();
272
+ if (el.tagName === "TABLE") {
273
+ parts.push(Array.from(el.querySelectorAll("tr")).map((row) => Array.from(row.querySelectorAll("th,td")).map((cell) => (cell.textContent || "").trim()).join(" ")).join("\n"));
274
+ return;
275
+ }
276
+ if (/^H[1-6]$/.test(el.tagName)) parts.push(`${"#".repeat(Number(el.tagName[1]))} ${own}`);
277
+ else if (el.tagName === "LI") parts.push(`- ${own}`);
278
+ else if (el.tagName === "P" && own) parts.push(own);
279
+ for (const child of Array.from(el.children)) walk(child);
280
+ };
281
+ for (const child of Array.from(root.childNodes)) walk(child);
282
+ return parts.filter(Boolean).join("\n\n");
283
+ }
284
+ function editorToJSON(editor) {
285
+ return editor.getJSON();
286
+ }
287
+ function editorFromJSON(editor, doc) {
288
+ editor.setJSON(doc);
289
+ }
290
+ function normalizeWordHtml(html, options = {}) {
291
+ const root = parse(html, options);
292
+ for (const element of Array.from(root.querySelectorAll("*"))) {
293
+ const style = element.getAttribute("style") || "";
294
+ if (/mso-/i.test(style)) {
295
+ const cleaned = style.split(";").filter((part) => !/mso-/i.test(part)).join(";");
296
+ if (cleaned) element.setAttribute("style", cleaned);
297
+ else element.removeAttribute("style");
298
+ }
299
+ const id = element.getAttribute("id") || "";
300
+ if (id.startsWith("docs-internal-guid") || element.hasAttribute("data-docs-internal-guid")) {
301
+ const parent = element.parentNode;
302
+ while (element.firstChild) parent.insertBefore(element.firstChild, element);
303
+ element.remove();
304
+ }
305
+ }
306
+ return root.innerHTML;
307
+ }
308
+ async function exportDocx(html, options = {}) {
309
+ const specifier = "docx";
310
+ const docxModule = await import(specifier).catch(() => {
311
+ throw new Error('[editkit/export] DOCX export requires the optional "docx" dependency');
312
+ });
313
+ const docx = docxModule;
314
+ const children = toPlainText(html, options).split("\n").filter(Boolean).map((line) => new docx.Paragraph(line));
315
+ const doc = new docx.Document({ sections: [{ children }] });
316
+ const blob = await docx.Packer.toBlob(doc);
317
+ return { blob, filename: options.filename || "editkit-document.docx" };
318
+ }
319
+ function printPdf(html, options = {}) {
320
+ const win = resolveWindow(options).open("", "_blank");
321
+ if (!win) throw new Error("[editkit/export] Pop-up blocked; allow pop-ups to print");
322
+ win.document.body.innerHTML = options.sanitize ? options.sanitize(html) : html;
323
+ win.focus();
324
+ win.print();
325
+ }
326
+ async function exportPdfViaAdapter(html, adapter, options = {}) {
327
+ const safe = options.sanitize ? options.sanitize(html) : html;
328
+ return { blob: await adapter(safe), filename: options.filename || "editkit-document.pdf" };
329
+ }
330
+ export {
331
+ editorFromJSON,
332
+ editorToJSON,
333
+ exportDocx,
334
+ exportPdfViaAdapter,
335
+ fromMarkdown,
336
+ normalizeWordHtml,
337
+ printPdf,
338
+ toCleanHtml,
339
+ toEmailHtml,
340
+ toMarkdown,
341
+ toPlainText
342
+ };
343
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export interface ExportOptions {\n window?: Window;\n sanitize?: (html: string) => string;\n inlineStyles?: boolean;\n}\n\nexport interface ExportResult {\n blob: Blob;\n filename: string;\n}\n\ntype AnyNode = Node & { childNodes: NodeListOf<ChildNode> };\n\nfunction resolveWindow(options: ExportOptions = {}): Window {\n const candidate = options.window || (globalThis as { window?: Window }).window;\n if (!candidate) throw new Error('[editkit/export] A DOM window is required');\n return candidate;\n}\n\nfunction parse(html: string, options: ExportOptions = {}): HTMLElement {\n const win = resolveWindow(options);\n const safe = options.sanitize ? options.sanitize(html) : html;\n const container = win.document.createElement('div');\n container.innerHTML = safe;\n return container;\n}\n\nfunction escapeMarkdown(text: string): string {\n return text.replace(/([\\\\`*_{}[\\]()#+\\-.!>])/g, '\\\\$1');\n}\n\nfunction escapeHtml(text: string): string {\n return text.replace(/[&<>\"']/g, char => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '\"': '&quot;', \"'\": '&#039;' })[char] || char);\n}\n\nfunction inlineToMarkdown(node: Node): string {\n if (node.nodeType === 3) return escapeMarkdown(node.textContent || '');\n if (node.nodeType !== 1) return '';\n const el = node as HTMLElement;\n const children = Array.from(el.childNodes).map(inlineToMarkdown).join('');\n switch (el.tagName) {\n case 'STRONG': case 'B': return `**${children}**`;\n case 'EM': case 'I': return `*${children}*`;\n case 'S': case 'DEL': case 'STRIKE': return `~~${children}~~`;\n case 'CODE': return `\\`${children}\\``;\n case 'A': return `[${children}](${el.getAttribute('href') || ''})`;\n case 'IMG': return `![${el.getAttribute('alt') || ''}](${el.getAttribute('src') || ''})`;\n case 'BR': return '\\n';\n default: return children;\n }\n}\n\nfunction tableToMarkdown(table: HTMLTableElement): string {\n const rows = Array.from(table.querySelectorAll('tr')).map(row => Array.from(row.querySelectorAll('th,td')).map(cell => (cell.textContent || '').trim().replace(/\\|/g, '\\\\|')));\n if (!rows.length) return '';\n const header = rows[0];\n const divider = header.map(() => '---');\n const body = rows.slice(1);\n return [header, divider, ...body].map(row => `| ${row.join(' | ')} |`).join('\\n') + '\\n\\n';\n}\n\nfunction blockToMarkdown(node: Node): string {\n if (node.nodeType === 3) {\n const text = node.textContent || '';\n return text.trim() ? `${text.trim()}\\n\\n` : '';\n }\n if (node.nodeType !== 1) return '';\n const el = node as HTMLElement;\n const children = Array.from(el.childNodes).map(blockToMarkdown).join('').trimEnd();\n switch (el.tagName) {\n case 'H1': case 'H2': case 'H3': case 'H4': case 'H5': case 'H6':\n return `${'#'.repeat(Number(el.tagName[1]))} ${children}\\n\\n`;\n case 'P': return `${inlineToMarkdown(el)}\\n\\n`;\n case 'UL': case 'OL': {\n const ordered = el.tagName === 'OL';\n return Array.from(el.children).map((item, index) => {\n const task = item.classList.contains('editkit-task-item');\n const marker = task ? (item.classList.contains('editkit-task-done') ? '- [x] ' : '- [ ] ') : ordered ? `${index + 1}. ` : '- ';\n return marker + inlineToMarkdown(item);\n }).join('\\n') + '\\n\\n';\n }\n case 'BLOCKQUOTE': return children.split('\\n').map(line => `> ${line}`).join('\\n') + '\\n\\n';\n case 'PRE': {\n const code = el.querySelector('code') || el;\n const language = el.getAttribute('data-language') || '';\n return `\\`\\`\\`${language}\\n${code.textContent || ''}\\n\\`\\`\\`\\n\\n`;\n }\n case 'HR': return '---\\n\\n';\n case 'TABLE': return tableToMarkdown(el as HTMLTableElement);\n case 'FIGURE': case 'DIV': {\n if (el.classList.contains('editkit-image-figure')) {\n const image = el.querySelector('img');\n const caption = el.querySelector('figcaption');\n return `![${caption?.textContent || image?.getAttribute('alt') || ''}](${image?.getAttribute('src') || ''})\\n\\n`;\n }\n if (el.classList.contains('editkit-panel') || el.hasAttribute('data-editkit-block')) {\n return `\\`\\`\\`html\\n${optionsFallback(el)}\\n\\`\\`\\`\\n\\n`;\n }\n return children + (children ? '\\n\\n' : '');\n }\n default: return children + (children ? '\\n\\n' : '');\n }\n}\n\nfunction optionsFallback(el: HTMLElement): string {\n return el.outerHTML;\n}\n\nexport function toMarkdown(html: string, options: ExportOptions = {}): string {\n const root = parse(html, options);\n return Array.from(root.childNodes).map(blockToMarkdown).join('').replace(/\\n{3,}/g, '\\n\\n').trim() + '\\n';\n}\n\nfunction inlineMarkdown(text: string): string {\n let value = escapeHtml(text);\n value = value.replace(/`([^`]+)`/g, '<code>$1</code>');\n value = value.replace(/\\*\\*([^*]+)\\*\\*/g, '<strong>$1</strong>');\n value = value.replace(/~~([^~]+)~~/g, '<s>$1</s>');\n value = value.replace(/\\*([^*]+)\\*/g, '<em>$1</em>');\n value = value.replace(/\\[([^\\]]+)\\]\\(([^)]+)\\)/g, (_match, label, href) => `<a href=\"${escapeHtml(href)}\">${label}</a>`);\n value = value.replace(/!\\[([^\\]]*)\\]\\(([^)]+)\\)/g, (_match, alt, src) => `<img src=\"${escapeHtml(src)}\" alt=\"${escapeHtml(alt)}\">`);\n return value;\n}\n\nexport function fromMarkdown(markdown: string, options: ExportOptions = {}): string {\n const lines = markdown.replace(/\\r/g, '').split('\\n');\n const output: string[] = [];\n let listType: 'ul' | 'ol' | null = null;\n let inCode = false;\n let codeLanguage = '';\n\n const closeList = () => {\n if (listType) {\n output.push(`</${listType}>`);\n listType = null;\n }\n };\n\n for (let index = 0; index < lines.length; index++) {\n const line = lines[index];\n if (line.startsWith('```')) {\n if (inCode) {\n output.push('</code></pre>');\n inCode = false;\n } else {\n closeList();\n codeLanguage = line.slice(3).trim();\n output.push(`<pre${codeLanguage ? ` data-language=\"${escapeHtml(codeLanguage)}\"` : ''}><code>`);\n inCode = true;\n }\n continue;\n }\n if (inCode) {\n output.push(escapeHtml(line));\n continue;\n }\n const heading = /^(#{1,6})\\s+(.*)$/.exec(line);\n if (heading) {\n closeList();\n output.push(`<h${heading[1].length}>${inlineMarkdown(heading[2])}</h${heading[1].length}>`);\n continue;\n }\n if (/^---+$/.test(line.trim())) {\n closeList();\n output.push('<hr>');\n continue;\n }\n const task = /^-\\s+\\[([ xX])\\]\\s+(.*)$/.exec(line);\n const bullet = /^-\\s+(.*)$/.exec(line);\n const ordered = /^\\d+\\.\\s+(.*)$/.exec(line);\n if (task || bullet || ordered) {\n const wanted = task || bullet ? 'ul' : 'ol';\n if (listType !== wanted) {\n closeList();\n output.push(`<${wanted}>`);\n listType = wanted;\n }\n const content = task ? task[2] : (bullet || ordered)![1];\n const className = task ? ` class=\"editkit-task-item${task[1] === ' ' ? '' : ' editkit-task-done'}\"` : '';\n output.push(`<li${className}>${inlineMarkdown(content)}</li>`);\n continue;\n }\n if (line.startsWith('> ')) {\n closeList();\n output.push(`<blockquote><p>${inlineMarkdown(line.slice(2))}</p></blockquote>`);\n continue;\n }\n if (line.trim().startsWith('|')) {\n closeList();\n const rows = lines.slice(index).filter(row => row.trim().startsWith('|'));\n const cells = rows.map(row => row.split('|').slice(1, -1).map(cell => cell.trim()).filter(cell => !/^---+$/.test(cell)));\n output.push('<table><thead><tr>' + cells[0].map(cell => `<th>${inlineMarkdown(cell)}</th>`).join('') + '</tr></thead><tbody>' + cells.slice(1).map(row => `<tr>${row.map(cell => `<td>${inlineMarkdown(cell)}</td>`).join('')}</tr>`).join('') + '</tbody></table>');\n index += rows.length - 1;\n continue;\n }\n if (!line.trim()) {\n closeList();\n continue;\n }\n closeList();\n output.push(`<p>${inlineMarkdown(line)}</p>`);\n }\n closeList();\n const html = output.join('');\n return options.sanitize ? options.sanitize(html) : html;\n}\n\nfunction cleanNode(node: Element, inlineStyles: boolean): void {\n if (node.hasAttribute('data-editkit-transient') || node.classList.contains('editkit-block-controls')) {\n node.remove();\n return;\n }\n for (const attr of Array.from(node.attributes)) {\n if (attr.name.startsWith('data-editkit') || attr.name === 'contenteditable' || attr.name === 'spellcheck') node.removeAttribute(attr.name);\n if (attr.name === 'class' && (attr.value.includes('editkit-') || attr.value.includes('mso'))) node.removeAttribute('class');\n if (attr.name === 'style' && !inlineStyles) node.removeAttribute('style');\n if (/^mso-|^aws-/i.test(attr.name)) node.removeAttribute(attr.name);\n }\n for (const child of Array.from(node.children)) cleanNode(child, inlineStyles);\n}\n\nexport function toCleanHtml(html: string, options: ExportOptions = {}): string {\n const root = parse(html, options);\n for (const child of Array.from(root.children)) cleanNode(child, Boolean(options.inlineStyles));\n return root.innerHTML;\n}\n\nexport function toEmailHtml(html: string, options: ExportOptions = {}): string {\n const root = parse(html, options);\n for (const svg of Array.from(root.querySelectorAll('svg'))) svg.remove();\n for (const columns of Array.from(root.querySelectorAll('.editkit-columns-container'))) {\n const table = resolveWindow(options).document.createElement('table');\n table.setAttribute('style', 'width:100%;max-width:600px');\n const row = table.insertRow();\n for (const column of Array.from(columns.querySelectorAll('.editkit-column-body'))) {\n const cell = row.insertCell();\n cell.innerHTML = column.innerHTML;\n }\n columns.replaceWith(table);\n }\n for (const button of Array.from(root.querySelectorAll('.editkit-button-block'))) {\n const table = resolveWindow(options).document.createElement('table');\n const row = table.insertRow();\n const cell = row.insertCell();\n cell.innerHTML = button.innerHTML;\n button.replaceWith(table);\n }\n for (const child of Array.from(root.children)) cleanNode(child, true);\n return `<div style=\"max-width:600px;margin:0 auto;font-family:Arial,sans-serif\">${root.innerHTML}</div>`;\n}\n\nexport function toPlainText(html: string, options: ExportOptions = {}): string {\n const root = parse(html, options);\n const parts: string[] = [];\n const walk = (node: Node) => {\n if (node.nodeType === 3) return;\n if (node.nodeType !== 1) return;\n const el = node as HTMLElement;\n const own = Array.from(el.childNodes).filter(child => child.nodeType === 3).map(child => child.textContent || '').join('').trim();\n if (el.tagName === 'TABLE') {\n parts.push(Array.from(el.querySelectorAll('tr')).map(row => Array.from(row.querySelectorAll('th,td')).map(cell => (cell.textContent || '').trim()).join('\\t')).join('\\n'));\n return;\n }\n if (/^H[1-6]$/.test(el.tagName)) parts.push(`${'#'.repeat(Number(el.tagName[1]))} ${own}`);\n else if (el.tagName === 'LI') parts.push(`- ${own}`);\n else if (el.tagName === 'P' && own) parts.push(own);\n for (const child of Array.from(el.children)) walk(child);\n };\n for (const child of Array.from(root.childNodes)) walk(child);\n return parts.filter(Boolean).join('\\n\\n');\n}\n\nexport function editorToJSON(editor: { getJSON(): unknown }): unknown {\n return editor.getJSON();\n}\n\nexport function editorFromJSON(editor: { setJSON(doc: unknown): void }, doc: unknown): void {\n editor.setJSON(doc);\n}\n\nexport function normalizeWordHtml(html: string, options: ExportOptions = {}): string {\n const root = parse(html, options);\n for (const element of Array.from(root.querySelectorAll('*'))) {\n const style = element.getAttribute('style') || '';\n if (/mso-/i.test(style)) {\n const cleaned = style.split(';').filter(part => !/mso-/i.test(part)).join(';');\n if (cleaned) element.setAttribute('style', cleaned);\n else element.removeAttribute('style');\n }\n const id = element.getAttribute('id') || '';\n if (id.startsWith('docs-internal-guid') || element.hasAttribute('data-docs-internal-guid')) {\n const parent = element.parentNode!;\n while (element.firstChild) parent.insertBefore(element.firstChild, element);\n element.remove();\n }\n }\n return root.innerHTML;\n}\n\nexport async function exportDocx(html: string, options: ExportOptions & { filename?: string } = {}): Promise<ExportResult> {\n const specifier = 'docx';\n const docxModule = await import(specifier).catch(() => {\n throw new Error('[editkit/export] DOCX export requires the optional \"docx\" dependency');\n });\n const docx = docxModule as Record<string, any>;\n const children = toPlainText(html, options).split('\\n').filter(Boolean).map(line => new docx.Paragraph(line));\n const doc = new docx.Document({ sections: [{ children }] });\n const blob = await docx.Packer.toBlob(doc);\n return { blob, filename: options.filename || 'editkit-document.docx' };\n}\n\nexport function printPdf(html: string, options: ExportOptions = {}): void {\n const win = resolveWindow(options).open('', '_blank');\n if (!win) throw new Error('[editkit/export] Pop-up blocked; allow pop-ups to print');\n win.document.body.innerHTML = options.sanitize ? options.sanitize(html) : html;\n win.focus();\n win.print();\n}\n\nexport async function exportPdfViaAdapter(\n html: string,\n adapter: (safeHtml: string) => Promise<Blob>,\n options: ExportOptions & { filename?: string } = {},\n): Promise<ExportResult> {\n const safe = options.sanitize ? options.sanitize(html) : html;\n return { blob: await adapter(safe), filename: options.filename || 'editkit-document.pdf' };\n}\n"],"mappings":";AAaA,SAAS,cAAc,UAAyB,CAAC,GAAW;AAC1D,QAAM,YAAY,QAAQ,UAAW,WAAmC;AACxE,MAAI,CAAC,UAAW,OAAM,IAAI,MAAM,2CAA2C;AAC3E,SAAO;AACT;AAEA,SAAS,MAAM,MAAc,UAAyB,CAAC,GAAgB;AACrE,QAAM,MAAM,cAAc,OAAO;AACjC,QAAM,OAAO,QAAQ,WAAW,QAAQ,SAAS,IAAI,IAAI;AACzD,QAAM,YAAY,IAAI,SAAS,cAAc,KAAK;AAClD,YAAU,YAAY;AACtB,SAAO;AACT;AAEA,SAAS,eAAe,MAAsB;AAC5C,SAAO,KAAK,QAAQ,4BAA4B,MAAM;AACxD;AAEA,SAAS,WAAW,MAAsB;AACxC,SAAO,KAAK,QAAQ,YAAY,WAAS,EAAE,KAAK,SAAS,KAAK,QAAQ,KAAK,QAAQ,KAAK,UAAU,KAAK,SAAS,GAAG,IAAI,KAAK,IAAI;AAClI;AAEA,SAAS,iBAAiB,MAAoB;AAC5C,MAAI,KAAK,aAAa,EAAG,QAAO,eAAe,KAAK,eAAe,EAAE;AACrE,MAAI,KAAK,aAAa,EAAG,QAAO;AAChC,QAAM,KAAK;AACX,QAAM,WAAW,MAAM,KAAK,GAAG,UAAU,EAAE,IAAI,gBAAgB,EAAE,KAAK,EAAE;AACxE,UAAQ,GAAG,SAAS;AAAA,IAClB,KAAK;AAAA,IAAU,KAAK;AAAK,aAAO,KAAK,QAAQ;AAAA,IAC7C,KAAK;AAAA,IAAM,KAAK;AAAK,aAAO,IAAI,QAAQ;AAAA,IACxC,KAAK;AAAA,IAAK,KAAK;AAAA,IAAO,KAAK;AAAU,aAAO,KAAK,QAAQ;AAA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C,EAAE,CAAC;AAC1D,QAAM,OAAO,MAAM,KAAK,OAAO,OAAO,GAAG;AACzC,SAAO,EAAE,MAAM,UAAU,QAAQ,YAAY,wBAAwB;AACvE;AAEO,SAAS,SAAS,MAAc,UAAyB,CAAC,GAAS;AACxE,QAAM,MAAM,cAAc,OAAO,EAAE,KAAK,IAAI,QAAQ;AACpD,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,yDAAyD;AACnF,MAAI,SAAS,KAAK,YAAY,QAAQ,WAAW,QAAQ,SAAS,IAAI,IAAI;AAC1E,MAAI,MAAM;AACV,MAAI,MAAM;AACZ;AAEA,eAAsB,oBACpB,MACA,SACA,UAAiD,CAAC,GAC3B;AACvB,QAAM,OAAO,QAAQ,WAAW,QAAQ,SAAS,IAAI,IAAI;AACzD,SAAO,EAAE,MAAM,MAAM,QAAQ,IAAI,GAAG,UAAU,QAAQ,YAAY,uBAAuB;AAC3F;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,55 @@
1
1
  {
2
2
  "name": "@editkit/export",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "2.0.0",
4
+ "description": "Optional import/export package for EditKit: Markdown, clean/email HTML, plain text, JSON, DOCX and PDF adapters.",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/ashikurweb/editKit-text-editor.git",
30
+ "directory": "packages/export"
31
+ },
32
+ "homepage": "https://github.com/ashikurweb/editKit-text-editor#readme",
33
+ "bugs": {
34
+ "url": "https://github.com/ashikurweb/editKit-text-editor/issues"
35
+ },
36
+ "keywords": [
37
+ "markdown",
38
+ "html to markdown",
39
+ "markdown to html",
40
+ "docx export",
41
+ "pdf export",
42
+ "email html",
43
+ "rich text export",
44
+ "editkit",
45
+ "@editkit/export"
46
+ ],
47
+ "license": "MIT",
48
+ "author": "Ashikur Rahman",
49
+ "devDependencies": {
50
+ "typescript": "^5.8.3"
51
+ },
52
+ "scripts": {
53
+ "build": "tsup src/index.ts --format esm,cjs --dts --sourcemap --clean --target es2022"
54
+ }
6
55
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.