fountainjs-editor 0.1.0 → 0.2.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/dist/fountainjs.cjs +113 -1
- package/dist/fountainjs.js +627 -118
- package/package.json +2 -2
- package/src/core/exporters/html-exporter.ts +118 -0
- package/src/core/exporters/json-exporter.ts +47 -0
- package/src/core/exporters/markdown-exporter.ts +83 -0
- package/src/extensions/index.ts +7 -0
- package/src/extensions/nodes/code-block.ts +40 -0
- package/src/extensions/plugins/mcp-integration.ts +267 -0
- package/src/extensions/plugins/syntax-highlight.ts +205 -0
- package/src/index.ts +5 -0
package/dist/fountainjs.js
CHANGED
|
@@ -1,84 +1,226 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { S as
|
|
5
|
-
import { A as
|
|
1
|
+
var b = Object.defineProperty;
|
|
2
|
+
var y = (o, t, e) => t in o ? b(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
|
|
3
|
+
var c = (o, t, e) => (y(o, typeof t != "symbol" ? t + "" : t, e), e);
|
|
4
|
+
import { S as x, N as k } from "./index-1c508d95.js";
|
|
5
|
+
import { A as rt, h as st, E as at, j as it, F as lt, M as ct, l as pt, a as mt, d as ht, R as dt, c as ut, b as gt, g as ft, e as wt, f as bt, T as yt, i as xt, u as kt, k as jt } from "./index-1c508d95.js";
|
|
6
6
|
import "react";
|
|
7
|
-
class
|
|
7
|
+
class u {
|
|
8
8
|
constructor(t, e) {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
c(this, "type");
|
|
10
|
+
c(this, "attrs");
|
|
11
11
|
this.type = t, this.attrs = e;
|
|
12
12
|
}
|
|
13
13
|
static fromJSON(t, e) {
|
|
14
14
|
const n = t.marks[e.type];
|
|
15
15
|
if (!n)
|
|
16
16
|
throw new Error(`Unknown mark type: ${e.type}`);
|
|
17
|
-
return new
|
|
17
|
+
return new u(n, { ...e.attrs });
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
class
|
|
20
|
+
class W extends x {
|
|
21
21
|
constructor(t, e, n) {
|
|
22
22
|
super(), this.path = t, this.offset = e, this.text = n;
|
|
23
23
|
}
|
|
24
24
|
apply(t) {
|
|
25
25
|
let e = t, n = [];
|
|
26
|
-
for (const
|
|
27
|
-
n.push(e), e = e.content[
|
|
26
|
+
for (const l of this.path)
|
|
27
|
+
n.push(e), e = e.content[l];
|
|
28
28
|
if (!e || !e.isText)
|
|
29
29
|
throw new Error("Target for InsertTextStep is not a text node.");
|
|
30
|
-
let
|
|
31
|
-
for (let
|
|
32
|
-
const
|
|
33
|
-
|
|
30
|
+
let a = e.withText((e.text || "").slice(0, this.offset) + this.text + (e.text || "").slice(this.offset));
|
|
31
|
+
for (let l = n.length - 1; l >= 0; l--) {
|
|
32
|
+
const p = n[l], m = [...p.content];
|
|
33
|
+
m[this.path[l]] = a, a = new k(p.type, p.attrs, m, p.text, p.marks);
|
|
34
34
|
}
|
|
35
|
-
return
|
|
35
|
+
return a;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
class
|
|
38
|
+
class g {
|
|
39
39
|
constructor(t) {
|
|
40
|
-
|
|
40
|
+
c(this, "spec");
|
|
41
41
|
this.spec = t;
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
class B {
|
|
45
|
+
highlightCode(t, e) {
|
|
46
|
+
const n = this.escapeHtml(t);
|
|
47
|
+
return `<pre><code class="language-${e}">${n}</code></pre>`;
|
|
48
|
+
}
|
|
49
|
+
escapeHtml(t) {
|
|
50
|
+
const e = {
|
|
51
|
+
"&": "&",
|
|
52
|
+
"<": "<",
|
|
53
|
+
">": ">",
|
|
54
|
+
'"': """,
|
|
55
|
+
"'": "'"
|
|
56
|
+
};
|
|
57
|
+
return t.replace(/[&<>"']/g, (n) => e[n]);
|
|
58
|
+
}
|
|
59
|
+
nodeToHtml(t) {
|
|
60
|
+
switch (t.type.name) {
|
|
61
|
+
case "doc":
|
|
62
|
+
return t.content.map((s) => this.nodeToHtml(s)).join(`
|
|
63
|
+
`);
|
|
64
|
+
case "heading":
|
|
65
|
+
const e = t.attrs.level || 1, n = t.content.map((s) => this.nodeToHtml(s)).join("");
|
|
66
|
+
return `<h${e}>${n}</h${e}>`;
|
|
67
|
+
case "paragraph":
|
|
68
|
+
return `<p>${t.content.map((s) => this.nodeToHtml(s)).join("")}</p>`;
|
|
69
|
+
case "text":
|
|
70
|
+
let a = t.text || "";
|
|
71
|
+
return t.marks && (t.marks.some((s) => s.type === "strong") && (a = `<strong>${a}</strong>`), t.marks.some((s) => s.type === "em") && (a = `<em>${a}</em>`)), a;
|
|
72
|
+
case "code-block":
|
|
73
|
+
const l = t.content.map((s) => s.text || "").join(`
|
|
74
|
+
`), p = t.attrs.language || "javascript";
|
|
75
|
+
return this.highlightCode(l, p);
|
|
76
|
+
case "bullet-list":
|
|
77
|
+
return `<ul>${t.content.map((s) => this.nodeToHtml(s)).join("")}</ul>`;
|
|
78
|
+
case "list-item":
|
|
79
|
+
return `<li>${t.content.map((s) => this.nodeToHtml(s)).join("")}</li>`;
|
|
80
|
+
case "table":
|
|
81
|
+
return `<table><tbody>${t.content.map((s) => this.nodeToHtml(s)).join("")}</tbody></table>`;
|
|
82
|
+
case "table-row":
|
|
83
|
+
return `<tr>${t.content.map((s) => this.nodeToHtml(s)).join("")}</tr>`;
|
|
84
|
+
case "table-cell":
|
|
85
|
+
return `<td>${t.content.map((s) => this.nodeToHtml(s)).join("")}</td>`;
|
|
86
|
+
case "image":
|
|
87
|
+
return `<img src="${t.attrs.src}" alt="${t.attrs.alt || ""}" style="max-width: 100%; border-radius: 8px; margin: 10px 0;" />`;
|
|
88
|
+
default:
|
|
89
|
+
return "";
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export(t) {
|
|
93
|
+
return `<!DOCTYPE html>
|
|
94
|
+
<html>
|
|
95
|
+
<head>
|
|
96
|
+
<meta charset="UTF-8">
|
|
97
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
98
|
+
<style>
|
|
99
|
+
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; line-height: 1.6; max-width: 800px; margin: 0 auto; padding: 20px; }
|
|
100
|
+
h1, h2, h3 { margin-top: 24px; margin-bottom: 16px; }
|
|
101
|
+
code { background: #f5f5f5; padding: 2px 6px; border-radius: 3px; font-family: 'Courier New', monospace; }
|
|
102
|
+
pre { background: #f5f5f5; padding: 12px; border-radius: 6px; overflow-x: auto; }
|
|
103
|
+
table { border-collapse: collapse; width: 100%; margin: 16px 0; }
|
|
104
|
+
table td, table th { border: 1px solid #ddd; padding: 8px; }
|
|
105
|
+
img { max-width: 100%; height: auto; }
|
|
106
|
+
ul, ol { margin: 16px 0; }
|
|
107
|
+
</style>
|
|
108
|
+
</head>
|
|
109
|
+
<body>
|
|
110
|
+
${this.nodeToHtml(t.doc)}
|
|
111
|
+
</body>
|
|
112
|
+
</html>`;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
class X {
|
|
116
|
+
nodeToMarkdown(t, e = 0) {
|
|
117
|
+
const n = " ".repeat(e);
|
|
118
|
+
switch (t.type.name) {
|
|
119
|
+
case "doc":
|
|
120
|
+
return t.content.map((i) => this.nodeToMarkdown(i, e)).join(`
|
|
121
|
+
|
|
122
|
+
`);
|
|
123
|
+
case "heading":
|
|
124
|
+
const r = t.attrs.level || 1, a = t.content.map((i) => this.nodeToMarkdown(i, e)).join("");
|
|
125
|
+
return `${"#".repeat(r)} ${a}`;
|
|
126
|
+
case "paragraph":
|
|
127
|
+
return t.content.map((i) => this.nodeToMarkdown(i, e)).join("");
|
|
128
|
+
case "text":
|
|
129
|
+
let l = t.text || "";
|
|
130
|
+
return t.marks && (t.marks.some((i) => i.type === "strong") && (l = `**${l}**`), t.marks.some((i) => i.type === "em") && (l = `*${l}*`)), l;
|
|
131
|
+
case "code-block":
|
|
132
|
+
const p = t.content.map((i) => i.text || "").join(`
|
|
133
|
+
`);
|
|
134
|
+
return `\`\`\`${t.attrs.language || ""}
|
|
135
|
+
${p}
|
|
136
|
+
\`\`\``;
|
|
137
|
+
case "bullet-list":
|
|
138
|
+
return t.content.map((i) => {
|
|
139
|
+
const d = this.nodeToMarkdown(i, e + 1);
|
|
140
|
+
return `${n}- ${d}`;
|
|
141
|
+
}).join(`
|
|
142
|
+
`);
|
|
143
|
+
case "list-item":
|
|
144
|
+
return t.content.map((i) => this.nodeToMarkdown(i, e)).join("");
|
|
145
|
+
case "table":
|
|
146
|
+
let h = "";
|
|
147
|
+
return t.content.forEach((i, d) => {
|
|
148
|
+
const s = i.content.map((w) => this.nodeToMarkdown(w, e)).join(" | ");
|
|
149
|
+
h += `| ${s} |
|
|
150
|
+
`, d === 0 && (h += `| ${s.split(" | ").map(() => "---").join(" | ")} |
|
|
151
|
+
`);
|
|
152
|
+
}), h;
|
|
153
|
+
case "table-cell":
|
|
154
|
+
return t.content.map((i) => this.nodeToMarkdown(i, e)).join("");
|
|
155
|
+
case "image":
|
|
156
|
+
return ``;
|
|
157
|
+
default:
|
|
158
|
+
return "";
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
export(t) {
|
|
162
|
+
return this.nodeToMarkdown(t.doc);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
class V {
|
|
166
|
+
nodeToJSON(t) {
|
|
167
|
+
const e = {
|
|
168
|
+
type: t.type.name
|
|
169
|
+
};
|
|
170
|
+
return t.attrs && Object.keys(t.attrs).length > 0 && (e.attrs = t.attrs), t.text && (e.text = t.text), t.marks && t.marks.length > 0 && (e.marks = t.marks.map((n) => ({
|
|
171
|
+
type: n.type,
|
|
172
|
+
attrs: n.attrs
|
|
173
|
+
}))), t.content && t.content.length > 0 && (e.content = t.content.map((n) => this.nodeToJSON(n))), e;
|
|
174
|
+
}
|
|
175
|
+
export(t) {
|
|
176
|
+
const e = this.nodeToJSON(t.doc);
|
|
177
|
+
return JSON.stringify(e, null, 2);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Import from JSON (for round-trip serialization)
|
|
181
|
+
*/
|
|
182
|
+
static import(t) {
|
|
183
|
+
return JSON.parse(t);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const j = { content: "block+", toDOM() {
|
|
45
187
|
return ["div", 0];
|
|
46
|
-
} },
|
|
188
|
+
} }, S = { content: "inline*", group: "block", toDOM() {
|
|
47
189
|
return ["p", 0];
|
|
48
|
-
} },
|
|
190
|
+
} }, T = { group: "inline" }, v = {
|
|
49
191
|
attrs: { level: { default: 1 } },
|
|
50
192
|
content: "inline*",
|
|
51
193
|
group: "block",
|
|
52
|
-
toDOM(
|
|
53
|
-
return [`h${
|
|
194
|
+
toDOM(o) {
|
|
195
|
+
return [`h${o.attrs.level}`, 0];
|
|
54
196
|
}
|
|
55
197
|
};
|
|
56
|
-
class
|
|
198
|
+
class $ {
|
|
57
199
|
// The function to get the node's position
|
|
58
200
|
constructor(t, e, n) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
201
|
+
c(this, "dom");
|
|
202
|
+
c(this, "contentDOM");
|
|
203
|
+
c(this, "img");
|
|
204
|
+
c(this, "getPos");
|
|
63
205
|
// --- Resize Logic ---
|
|
64
|
-
|
|
206
|
+
c(this, "onResizeStart", (t) => {
|
|
65
207
|
t.preventDefault();
|
|
66
|
-
const e = t.clientX, n = this.dom.offsetWidth,
|
|
67
|
-
const
|
|
68
|
-
this.dom.style.width = `${
|
|
69
|
-
},
|
|
70
|
-
window.removeEventListener("mousemove",
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
208
|
+
const e = t.clientX, n = this.dom.offsetWidth, r = (l) => {
|
|
209
|
+
const p = n + (l.clientX - e);
|
|
210
|
+
this.dom.style.width = `${p}px`;
|
|
211
|
+
}, a = () => {
|
|
212
|
+
window.removeEventListener("mousemove", r), window.removeEventListener("mouseup", a);
|
|
213
|
+
const l = this.getPos();
|
|
214
|
+
if (l === void 0)
|
|
73
215
|
return;
|
|
74
|
-
const
|
|
75
|
-
this.view.editor.dispatch(
|
|
216
|
+
const p = { ...this.node.attrs, width: this.dom.style.width }, m = [l], h = this.view.editor.createTransaction().setNodeAttrs(m, p);
|
|
217
|
+
this.view.editor.dispatch(h);
|
|
76
218
|
};
|
|
77
|
-
window.addEventListener("mousemove",
|
|
219
|
+
window.addEventListener("mousemove", r), window.addEventListener("mouseup", a);
|
|
78
220
|
});
|
|
79
221
|
this.node = t, this.view = e, this.getPos = n, this.dom = document.createElement("figure"), this.dom.style.position = "relative", this.dom.style.margin = "1rem 0", this.dom.style.display = "inline-block", this.img = document.createElement("img"), this.updateImageAttributes(t.attrs), this.contentDOM = document.createElement("div");
|
|
80
|
-
const
|
|
81
|
-
|
|
222
|
+
const r = document.createElement("div");
|
|
223
|
+
r.style.position = "absolute", r.style.bottom = "5px", r.style.right = "5px", r.style.width = "10px", r.style.height = "10px", r.style.backgroundColor = "#007bff", r.style.cursor = "nwse-resize", r.style.border = "1px solid white", this.dom.appendChild(this.img), this.dom.appendChild(this.contentDOM), this.dom.appendChild(r), r.addEventListener("mousedown", this.onResizeStart);
|
|
82
224
|
}
|
|
83
225
|
// Called by the main EditorView when the node changes
|
|
84
226
|
update(t) {
|
|
@@ -89,131 +231,498 @@ class S {
|
|
|
89
231
|
this.img.src = t.src, this.img.alt = t.alt, this.img.title = t.title, this.dom.style.width = t.width, this.img.style.width = "100%";
|
|
90
232
|
}
|
|
91
233
|
}
|
|
92
|
-
const
|
|
234
|
+
const C = {
|
|
93
235
|
group: "block",
|
|
94
236
|
content: "figcaption?",
|
|
95
237
|
attrs: { src: { default: "" }, alt: { default: "" }, title: { default: "" }, width: { default: "100%" } },
|
|
96
|
-
toDOM: (
|
|
97
|
-
const { src: t, alt: e, title: n, width:
|
|
98
|
-
return ["figure", { style: `width: ${
|
|
238
|
+
toDOM: (o) => {
|
|
239
|
+
const { src: t, alt: e, title: n, width: r } = o.attrs;
|
|
240
|
+
return ["figure", { style: `width: ${r};` }, ["img", { src: t, alt: e, title: n }], 0];
|
|
99
241
|
},
|
|
100
|
-
nodeView:
|
|
242
|
+
nodeView: $
|
|
101
243
|
}, M = {
|
|
102
244
|
content: "inline*",
|
|
103
245
|
toDOM: () => ["figcaption", { style: "text-align: center; color: #666; font-style: italic;" }, 0]
|
|
104
|
-
},
|
|
246
|
+
}, O = {
|
|
105
247
|
group: "block",
|
|
106
248
|
content: "table_row+",
|
|
107
249
|
toDOM() {
|
|
108
250
|
return ["table", { style: "border-collapse: collapse; width: 100%;" }, ["tbody", 0]];
|
|
109
251
|
}
|
|
110
|
-
},
|
|
252
|
+
}, P = { content: "table_cell+", toDOM() {
|
|
111
253
|
return ["tr", 0];
|
|
112
|
-
} },
|
|
254
|
+
} }, E = {
|
|
113
255
|
content: "paragraph+",
|
|
114
256
|
attrs: { colspan: { default: 1 }, rowspan: { default: 1 } },
|
|
115
|
-
toDOM(
|
|
116
|
-
return ["td", { style: "border: 1px solid #ddd; padding: 8px;", ...
|
|
257
|
+
toDOM(o) {
|
|
258
|
+
return ["td", { style: "border: 1px solid #ddd; padding: 8px;", ...o.attrs }, 0];
|
|
117
259
|
}
|
|
118
|
-
},
|
|
260
|
+
}, N = {
|
|
119
261
|
group: "block",
|
|
120
262
|
content: "list_item+",
|
|
121
263
|
// Must contain one or more list_item nodes
|
|
122
264
|
toDOM() {
|
|
123
265
|
return ["ul", 0];
|
|
124
266
|
}
|
|
125
|
-
},
|
|
267
|
+
}, D = {
|
|
126
268
|
// A list item can contain paragraphs, and even nested lists.
|
|
127
269
|
content: "paragraph+ (bullet_list)?",
|
|
128
270
|
toDOM() {
|
|
129
271
|
return ["li", 0];
|
|
130
272
|
}
|
|
131
|
-
},
|
|
273
|
+
}, H = {
|
|
274
|
+
name: "code-block",
|
|
275
|
+
group: "block",
|
|
276
|
+
atom: !1,
|
|
277
|
+
code: !0,
|
|
278
|
+
attrs: {
|
|
279
|
+
language: { default: "javascript" },
|
|
280
|
+
lineNumbers: { default: !1 }
|
|
281
|
+
},
|
|
282
|
+
parseDOM: [
|
|
283
|
+
{
|
|
284
|
+
tag: "pre",
|
|
285
|
+
preserveWhitespace: "full",
|
|
286
|
+
getAttrs(o) {
|
|
287
|
+
return {
|
|
288
|
+
language: o.getAttribute("data-language") || "javascript",
|
|
289
|
+
lineNumbers: o.getAttribute("data-line-numbers") === "true"
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
],
|
|
294
|
+
toDOM() {
|
|
295
|
+
return [
|
|
296
|
+
"pre",
|
|
297
|
+
{
|
|
298
|
+
"data-language": this.attrs.language,
|
|
299
|
+
"data-line-numbers": this.attrs.lineNumbers ? "true" : "false",
|
|
300
|
+
class: `language-${this.attrs.language}`
|
|
301
|
+
},
|
|
302
|
+
["code", 0]
|
|
303
|
+
];
|
|
304
|
+
}
|
|
305
|
+
}, A = {
|
|
306
|
+
...H,
|
|
307
|
+
isInline: !1
|
|
308
|
+
}, I = { toDOM() {
|
|
132
309
|
return ["strong", 0];
|
|
133
|
-
} },
|
|
310
|
+
} }, L = { toDOM() {
|
|
134
311
|
return ["em", 0];
|
|
135
312
|
} }, _ = 100;
|
|
136
|
-
function
|
|
313
|
+
function R() {
|
|
137
314
|
return { done: [], undone: [] };
|
|
138
315
|
}
|
|
139
|
-
const
|
|
316
|
+
const Y = new g({
|
|
140
317
|
state: {
|
|
141
|
-
init:
|
|
142
|
-
apply: (
|
|
143
|
-
if (
|
|
144
|
-
const e = [...t.done,
|
|
318
|
+
init: R,
|
|
319
|
+
apply: (o, t) => {
|
|
320
|
+
if (o.steps.length > 0) {
|
|
321
|
+
const e = [...t.done, o];
|
|
145
322
|
return e.length > _ && e.shift(), { done: e, undone: [] };
|
|
146
323
|
}
|
|
147
324
|
return t;
|
|
148
325
|
}
|
|
149
326
|
}
|
|
150
327
|
});
|
|
151
|
-
function
|
|
328
|
+
function G(o) {
|
|
152
329
|
return console.log("Undo command called (not implemented)"), !1;
|
|
153
330
|
}
|
|
154
|
-
function
|
|
331
|
+
function K(o) {
|
|
155
332
|
return console.log("Redo command called (not implemented)"), !1;
|
|
156
333
|
}
|
|
157
|
-
const
|
|
334
|
+
const Q = new g({});
|
|
335
|
+
class U {
|
|
336
|
+
constructor(t = {}) {
|
|
337
|
+
c(this, "config");
|
|
338
|
+
c(this, "languageMap", {
|
|
339
|
+
js: "javascript",
|
|
340
|
+
ts: "typescript",
|
|
341
|
+
py: "python",
|
|
342
|
+
rb: "ruby",
|
|
343
|
+
go: "go",
|
|
344
|
+
rs: "rust",
|
|
345
|
+
java: "java",
|
|
346
|
+
cpp: "cpp",
|
|
347
|
+
c: "c",
|
|
348
|
+
cs: "csharp",
|
|
349
|
+
php: "php",
|
|
350
|
+
swift: "swift",
|
|
351
|
+
kotlin: "kotlin",
|
|
352
|
+
sql: "sql",
|
|
353
|
+
html: "html",
|
|
354
|
+
css: "css",
|
|
355
|
+
json: "json",
|
|
356
|
+
xml: "xml",
|
|
357
|
+
yaml: "yaml",
|
|
358
|
+
yml: "yaml",
|
|
359
|
+
bash: "bash",
|
|
360
|
+
sh: "bash",
|
|
361
|
+
r: "r",
|
|
362
|
+
matlab: "matlab",
|
|
363
|
+
scala: "scala"
|
|
364
|
+
});
|
|
365
|
+
this.config = {
|
|
366
|
+
theme: "default",
|
|
367
|
+
lineNumbers: !0,
|
|
368
|
+
...t
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Highlight code in a given language
|
|
373
|
+
*/
|
|
374
|
+
highlight(t, e) {
|
|
375
|
+
const n = this.normalizeLanguage(e), r = `hljs-${this.config.theme}`;
|
|
376
|
+
let a = t;
|
|
377
|
+
return this.config.lineNumbers && (a = this.addLineNumbers(t)), a = this.escapeHtml(a), `<pre class="${r}"><code class="language-${n} hljs">${a}</code></pre>`;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Generate CSS for syntax highlighting
|
|
381
|
+
*/
|
|
382
|
+
generateCSS() {
|
|
383
|
+
return `
|
|
384
|
+
.hljs {
|
|
385
|
+
display: block;
|
|
386
|
+
overflow-x: auto;
|
|
387
|
+
padding: 0.5em;
|
|
388
|
+
color: #333;
|
|
389
|
+
background: #f5f5f5;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
.hljs-keyword,
|
|
393
|
+
.hljs-selector-tag,
|
|
394
|
+
.hljs-literal {
|
|
395
|
+
color: #0077aa;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
.hljs-string {
|
|
399
|
+
color: #669900;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
.hljs-number {
|
|
403
|
+
color: #924900;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
.hljs-attr,
|
|
407
|
+
.hljs-attribute {
|
|
408
|
+
color: #d19a66;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
.hljs-comment {
|
|
412
|
+
color: #aaa;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
.hljs-function .hljs-title {
|
|
416
|
+
color: #dd4814;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
.hljs-class .hljs-title {
|
|
420
|
+
color: #dd4814;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
.hljs-dark {
|
|
424
|
+
background: #1e1e1e;
|
|
425
|
+
color: #d4d4d4;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
.hljs-dark .hljs-keyword,
|
|
429
|
+
.hljs-dark .hljs-selector-tag {
|
|
430
|
+
color: #569cd6;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
.hljs-dark .hljs-string {
|
|
434
|
+
color: #ce9178;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
.hljs-dark .hljs-number {
|
|
438
|
+
color: #b5cea8;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
.hljs-dark .hljs-comment {
|
|
442
|
+
color: #6a9955;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
.line-number {
|
|
446
|
+
display: inline-block;
|
|
447
|
+
width: 50px;
|
|
448
|
+
text-align: right;
|
|
449
|
+
padding-right: 10px;
|
|
450
|
+
margin-right: 10px;
|
|
451
|
+
border-right: 1px solid #ddd;
|
|
452
|
+
color: #999;
|
|
453
|
+
user-select: none;
|
|
454
|
+
}
|
|
455
|
+
`;
|
|
456
|
+
}
|
|
457
|
+
normalizeLanguage(t) {
|
|
458
|
+
const e = t.toLowerCase();
|
|
459
|
+
return this.languageMap[e] || e;
|
|
460
|
+
}
|
|
461
|
+
addLineNumbers(t) {
|
|
462
|
+
return t.split(`
|
|
463
|
+
`).map((n, r) => `<span class="line-number">${r + 1}</span>${n}`).join(`
|
|
464
|
+
`);
|
|
465
|
+
}
|
|
466
|
+
escapeHtml(t) {
|
|
467
|
+
const e = {
|
|
468
|
+
"&": "&",
|
|
469
|
+
"<": "<",
|
|
470
|
+
">": ">",
|
|
471
|
+
'"': """,
|
|
472
|
+
"'": "'"
|
|
473
|
+
};
|
|
474
|
+
return t.replace(/[&<>"']/g, (n) => e[n]);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
class Z {
|
|
478
|
+
constructor(t) {
|
|
479
|
+
c(this, "highlighter");
|
|
480
|
+
this.highlighter = new U(t);
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Get the highlighter instance
|
|
484
|
+
*/
|
|
485
|
+
getHighlighter() {
|
|
486
|
+
return this.highlighter;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Get CSS for syntax highlighting
|
|
490
|
+
*/
|
|
491
|
+
getCSS() {
|
|
492
|
+
return this.highlighter.generateCSS();
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
class q {
|
|
496
|
+
constructor(t) {
|
|
497
|
+
c(this, "mcpServerUrl");
|
|
498
|
+
c(this, "tools", []);
|
|
499
|
+
this.mcpServerUrl = t, this.registerDefaultTools();
|
|
500
|
+
}
|
|
501
|
+
registerDefaultTools() {
|
|
502
|
+
this.tools = [
|
|
503
|
+
{
|
|
504
|
+
name: "generate_content",
|
|
505
|
+
description: "Generate new content in specified format",
|
|
506
|
+
inputSchema: {
|
|
507
|
+
type: "object",
|
|
508
|
+
properties: {
|
|
509
|
+
prompt: {
|
|
510
|
+
type: "string",
|
|
511
|
+
description: "What to generate"
|
|
512
|
+
},
|
|
513
|
+
format: {
|
|
514
|
+
type: "string",
|
|
515
|
+
enum: ["markdown", "html", "json", "fountain"],
|
|
516
|
+
description: "Output format"
|
|
517
|
+
},
|
|
518
|
+
language: {
|
|
519
|
+
type: "string",
|
|
520
|
+
description: "Programming language (if code)"
|
|
521
|
+
}
|
|
522
|
+
},
|
|
523
|
+
required: ["prompt", "format"]
|
|
524
|
+
}
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
name: "improve_content",
|
|
528
|
+
description: "Improve existing content",
|
|
529
|
+
inputSchema: {
|
|
530
|
+
type: "object",
|
|
531
|
+
properties: {
|
|
532
|
+
content: {
|
|
533
|
+
type: "string",
|
|
534
|
+
description: "Content to improve"
|
|
535
|
+
},
|
|
536
|
+
aspect: {
|
|
537
|
+
type: "string",
|
|
538
|
+
enum: ["clarity", "grammar", "tone", "structure"],
|
|
539
|
+
description: "What to improve"
|
|
540
|
+
}
|
|
541
|
+
},
|
|
542
|
+
required: ["content", "aspect"]
|
|
543
|
+
}
|
|
544
|
+
},
|
|
545
|
+
{
|
|
546
|
+
name: "transform_format",
|
|
547
|
+
description: "Transform content between formats",
|
|
548
|
+
inputSchema: {
|
|
549
|
+
type: "object",
|
|
550
|
+
properties: {
|
|
551
|
+
content: {
|
|
552
|
+
type: "string",
|
|
553
|
+
description: "Content to transform"
|
|
554
|
+
},
|
|
555
|
+
fromFormat: {
|
|
556
|
+
type: "string",
|
|
557
|
+
enum: ["markdown", "html", "json", "fountain", "text"]
|
|
558
|
+
},
|
|
559
|
+
toFormat: {
|
|
560
|
+
type: "string",
|
|
561
|
+
enum: ["markdown", "html", "json", "fountain"]
|
|
562
|
+
}
|
|
563
|
+
},
|
|
564
|
+
required: ["content", "fromFormat", "toFormat"]
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
];
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Connect to an MCP server
|
|
571
|
+
* Server can be hosted anywhere - local, cloud, enterprise
|
|
572
|
+
*/
|
|
573
|
+
async connectToMCPServer(t) {
|
|
574
|
+
this.mcpServerUrl = t, console.log(`Connected to MCP server: ${t}`);
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Register custom tools for specific AI use cases
|
|
578
|
+
*/
|
|
579
|
+
registerTool(t) {
|
|
580
|
+
this.tools.push(t);
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Get available tools for this AI
|
|
584
|
+
*/
|
|
585
|
+
getAvailableTools() {
|
|
586
|
+
return this.tools;
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Transform content using AI through MCP
|
|
590
|
+
* Works with ANY MCP-compatible AI service
|
|
591
|
+
*/
|
|
592
|
+
async transformContent(t) {
|
|
593
|
+
if (!this.mcpServerUrl)
|
|
594
|
+
throw new Error("MCP server not configured. Call connectToMCPServer() first.");
|
|
595
|
+
const e = this.buildSystemPrompt(t), r = {
|
|
596
|
+
content: this.buildUserPrompt(t),
|
|
597
|
+
systemPrompt: e,
|
|
598
|
+
tools: this.tools
|
|
599
|
+
}, a = await this.sendToMCP(r);
|
|
600
|
+
return this.extractContent(a);
|
|
601
|
+
}
|
|
602
|
+
buildSystemPrompt(t) {
|
|
603
|
+
return `You are a helpful content transformation AI.
|
|
604
|
+
The user has content in ${t.contentType} format.
|
|
605
|
+
Help them ${t.operation} their content.
|
|
606
|
+
${t.language ? `Programming language: ${t.language}` : ""}
|
|
607
|
+
${t.context ? `Context: ${t.context}` : ""}`;
|
|
608
|
+
}
|
|
609
|
+
buildUserPrompt(t) {
|
|
610
|
+
switch (t.operation) {
|
|
611
|
+
case "generate":
|
|
612
|
+
return `Generate new content: ${t.content}`;
|
|
613
|
+
case "improve":
|
|
614
|
+
return `Improve this content:
|
|
615
|
+
${t.content}`;
|
|
616
|
+
case "transform":
|
|
617
|
+
return `Transform this content to a better format:
|
|
618
|
+
${t.content}`;
|
|
619
|
+
case "summarize":
|
|
620
|
+
return `Summarize this content:
|
|
621
|
+
${t.content}`;
|
|
622
|
+
case "expand":
|
|
623
|
+
return `Expand on this content:
|
|
624
|
+
${t.content}`;
|
|
625
|
+
default:
|
|
626
|
+
return t.content;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
async sendToMCP(t) {
|
|
630
|
+
if (!this.mcpServerUrl)
|
|
631
|
+
throw new Error("MCP server URL not set");
|
|
632
|
+
try {
|
|
633
|
+
const e = await fetch(`${this.mcpServerUrl}/messages`, {
|
|
634
|
+
method: "POST",
|
|
635
|
+
headers: { "Content-Type": "application/json" },
|
|
636
|
+
body: JSON.stringify(t)
|
|
637
|
+
});
|
|
638
|
+
if (!e.ok)
|
|
639
|
+
throw new Error(`MCP server error: ${e.statusText}`);
|
|
640
|
+
return await e.json();
|
|
641
|
+
} catch (e) {
|
|
642
|
+
throw console.error("MCP request failed:", e), e;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
extractContent(t) {
|
|
646
|
+
return t.content.filter((n) => n.type === "text").map((n) => n.text || "").join(`
|
|
647
|
+
`);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
async function tt(o, t, e = "markdown") {
|
|
651
|
+
const n = {
|
|
652
|
+
content: o,
|
|
653
|
+
contentType: e,
|
|
654
|
+
operation: "generate"
|
|
655
|
+
};
|
|
656
|
+
return t.transformContent(n);
|
|
657
|
+
}
|
|
658
|
+
const et = {
|
|
158
659
|
nodes: {
|
|
159
|
-
doc:
|
|
160
|
-
paragraph:
|
|
161
|
-
text:
|
|
162
|
-
heading:
|
|
163
|
-
image_super:
|
|
660
|
+
doc: j,
|
|
661
|
+
paragraph: S,
|
|
662
|
+
text: T,
|
|
663
|
+
heading: v,
|
|
664
|
+
image_super: C,
|
|
164
665
|
figcaption: M,
|
|
165
|
-
table:
|
|
166
|
-
table_row:
|
|
167
|
-
table_cell:
|
|
168
|
-
bullet_list:
|
|
169
|
-
list_item:
|
|
666
|
+
table: O,
|
|
667
|
+
table_row: P,
|
|
668
|
+
table_cell: E,
|
|
669
|
+
bullet_list: N,
|
|
670
|
+
list_item: D,
|
|
671
|
+
code_block: A
|
|
170
672
|
},
|
|
171
673
|
marks: {
|
|
172
|
-
strong:
|
|
173
|
-
em:
|
|
674
|
+
strong: I,
|
|
675
|
+
em: L
|
|
174
676
|
}
|
|
175
677
|
};
|
|
176
678
|
export {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
679
|
+
rt as AddMarkStep,
|
|
680
|
+
et as CoreSchemaSpec,
|
|
681
|
+
st as Editor,
|
|
682
|
+
at as EditorState,
|
|
683
|
+
it as EditorView,
|
|
684
|
+
lt as FountainEditor,
|
|
685
|
+
B as HTMLExporter,
|
|
686
|
+
W as InsertTextStep,
|
|
687
|
+
V as JSONExporter,
|
|
688
|
+
q as MCPIntegration,
|
|
689
|
+
u as Mark,
|
|
690
|
+
ct as MarkType,
|
|
691
|
+
X as MarkdownExporter,
|
|
692
|
+
pt as Navigator,
|
|
693
|
+
k as Node,
|
|
694
|
+
mt as NodeType,
|
|
695
|
+
g as Plugin,
|
|
696
|
+
ht as RemoveMarkStep,
|
|
697
|
+
dt as ReplaceStep,
|
|
698
|
+
ut as ReplaceTextStep,
|
|
699
|
+
gt as Schema,
|
|
700
|
+
ft as Selection,
|
|
701
|
+
wt as SetNodeAttrsStep,
|
|
702
|
+
x as Step,
|
|
703
|
+
Z as SyntaxHighlightPlugin,
|
|
704
|
+
bt as Transaction,
|
|
705
|
+
yt as Transform,
|
|
706
|
+
N as bulletList,
|
|
707
|
+
A as codeBlock,
|
|
708
|
+
xt as createEditor,
|
|
709
|
+
j as doc,
|
|
710
|
+
L as em,
|
|
203
711
|
M as figcaption,
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
E as
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
712
|
+
tt as generateContentWithAI,
|
|
713
|
+
v as heading,
|
|
714
|
+
Y as historyPlugin,
|
|
715
|
+
C as imageSuper,
|
|
716
|
+
D as listItem,
|
|
717
|
+
Q as markdownShortcutsPlugin,
|
|
718
|
+
S as paragraph,
|
|
719
|
+
K as redo,
|
|
720
|
+
I as strong,
|
|
721
|
+
O as table,
|
|
722
|
+
E as tableCell,
|
|
723
|
+
P as tableRow,
|
|
724
|
+
T as text,
|
|
725
|
+
G as undo,
|
|
726
|
+
kt as useFountain,
|
|
727
|
+
jt as useNavigatorState
|
|
219
728
|
};
|