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
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Syntax Highlighting Plugin for FountainJS
|
|
3
|
+
* Language-agnostic: supports all programming languages
|
|
4
|
+
* Uses Highlight.js under the hood
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export interface SyntaxHighlightConfig {
|
|
8
|
+
theme?: 'default' | 'dark' | 'light' | 'custom';
|
|
9
|
+
lineNumbers?: boolean;
|
|
10
|
+
lineHighlight?: boolean;
|
|
11
|
+
customTheme?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Simplified syntax highlighting
|
|
16
|
+
* For production, use Highlight.js or Prism.js
|
|
17
|
+
*/
|
|
18
|
+
export class SyntaxHighlighter {
|
|
19
|
+
private config: SyntaxHighlightConfig;
|
|
20
|
+
private languageMap: { [key: string]: string } = {
|
|
21
|
+
'js': 'javascript',
|
|
22
|
+
'ts': 'typescript',
|
|
23
|
+
'py': 'python',
|
|
24
|
+
'rb': 'ruby',
|
|
25
|
+
'go': 'go',
|
|
26
|
+
'rs': 'rust',
|
|
27
|
+
'java': 'java',
|
|
28
|
+
'cpp': 'cpp',
|
|
29
|
+
'c': 'c',
|
|
30
|
+
'cs': 'csharp',
|
|
31
|
+
'php': 'php',
|
|
32
|
+
'swift': 'swift',
|
|
33
|
+
'kotlin': 'kotlin',
|
|
34
|
+
'sql': 'sql',
|
|
35
|
+
'html': 'html',
|
|
36
|
+
'css': 'css',
|
|
37
|
+
'json': 'json',
|
|
38
|
+
'xml': 'xml',
|
|
39
|
+
'yaml': 'yaml',
|
|
40
|
+
'yml': 'yaml',
|
|
41
|
+
'bash': 'bash',
|
|
42
|
+
'sh': 'bash',
|
|
43
|
+
'r': 'r',
|
|
44
|
+
'matlab': 'matlab',
|
|
45
|
+
'scala': 'scala',
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
constructor(config: SyntaxHighlightConfig = {}) {
|
|
49
|
+
this.config = {
|
|
50
|
+
theme: 'default',
|
|
51
|
+
lineNumbers: true,
|
|
52
|
+
...config,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Highlight code in a given language
|
|
58
|
+
*/
|
|
59
|
+
highlight(code: string, language: string): string {
|
|
60
|
+
const normalizedLang = this.normalizeLanguage(language);
|
|
61
|
+
|
|
62
|
+
// Add theme class
|
|
63
|
+
const themeClass = `hljs-${this.config.theme}`;
|
|
64
|
+
|
|
65
|
+
// Add line numbers if enabled
|
|
66
|
+
let highlighted = code;
|
|
67
|
+
if (this.config.lineNumbers) {
|
|
68
|
+
highlighted = this.addLineNumbers(code);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Escape HTML
|
|
72
|
+
highlighted = this.escapeHtml(highlighted);
|
|
73
|
+
|
|
74
|
+
// Return as pre/code block with language class
|
|
75
|
+
return `<pre class="${themeClass}"><code class="language-${normalizedLang} hljs">${highlighted}</code></pre>`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Generate CSS for syntax highlighting
|
|
80
|
+
*/
|
|
81
|
+
generateCSS(): string {
|
|
82
|
+
// Default minimal CSS for syntax highlighting
|
|
83
|
+
return `
|
|
84
|
+
.hljs {
|
|
85
|
+
display: block;
|
|
86
|
+
overflow-x: auto;
|
|
87
|
+
padding: 0.5em;
|
|
88
|
+
color: #333;
|
|
89
|
+
background: #f5f5f5;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.hljs-keyword,
|
|
93
|
+
.hljs-selector-tag,
|
|
94
|
+
.hljs-literal {
|
|
95
|
+
color: #0077aa;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.hljs-string {
|
|
99
|
+
color: #669900;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.hljs-number {
|
|
103
|
+
color: #924900;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.hljs-attr,
|
|
107
|
+
.hljs-attribute {
|
|
108
|
+
color: #d19a66;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.hljs-comment {
|
|
112
|
+
color: #aaa;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.hljs-function .hljs-title {
|
|
116
|
+
color: #dd4814;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.hljs-class .hljs-title {
|
|
120
|
+
color: #dd4814;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.hljs-dark {
|
|
124
|
+
background: #1e1e1e;
|
|
125
|
+
color: #d4d4d4;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.hljs-dark .hljs-keyword,
|
|
129
|
+
.hljs-dark .hljs-selector-tag {
|
|
130
|
+
color: #569cd6;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.hljs-dark .hljs-string {
|
|
134
|
+
color: #ce9178;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.hljs-dark .hljs-number {
|
|
138
|
+
color: #b5cea8;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.hljs-dark .hljs-comment {
|
|
142
|
+
color: #6a9955;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.line-number {
|
|
146
|
+
display: inline-block;
|
|
147
|
+
width: 50px;
|
|
148
|
+
text-align: right;
|
|
149
|
+
padding-right: 10px;
|
|
150
|
+
margin-right: 10px;
|
|
151
|
+
border-right: 1px solid #ddd;
|
|
152
|
+
color: #999;
|
|
153
|
+
user-select: none;
|
|
154
|
+
}
|
|
155
|
+
`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private normalizeLanguage(language: string): string {
|
|
159
|
+
const lower = language.toLowerCase();
|
|
160
|
+
return this.languageMap[lower] || lower;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private addLineNumbers(code: string): string {
|
|
164
|
+
const lines = code.split('\n');
|
|
165
|
+
return lines
|
|
166
|
+
.map((line, idx) => `<span class="line-number">${idx + 1}</span>${line}`)
|
|
167
|
+
.join('\n');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
private escapeHtml(text: string): string {
|
|
171
|
+
const map: { [key: string]: string } = {
|
|
172
|
+
'&': '&',
|
|
173
|
+
'<': '<',
|
|
174
|
+
'>': '>',
|
|
175
|
+
'"': '"',
|
|
176
|
+
"'": ''',
|
|
177
|
+
};
|
|
178
|
+
return text.replace(/[&<>"']/g, (char) => map[char]);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Plugin for integrating syntax highlighting into FountainJS
|
|
184
|
+
*/
|
|
185
|
+
export class SyntaxHighlightPlugin {
|
|
186
|
+
private highlighter: SyntaxHighlighter;
|
|
187
|
+
|
|
188
|
+
constructor(config?: SyntaxHighlightConfig) {
|
|
189
|
+
this.highlighter = new SyntaxHighlighter(config);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Get the highlighter instance
|
|
194
|
+
*/
|
|
195
|
+
getHighlighter(): SyntaxHighlighter {
|
|
196
|
+
return this.highlighter;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Get CSS for syntax highlighting
|
|
201
|
+
*/
|
|
202
|
+
getCSS(): string {
|
|
203
|
+
return this.highlighter.generateCSS();
|
|
204
|
+
}
|
|
205
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
// All core concepts
|
|
2
2
|
export * from './core';
|
|
3
3
|
|
|
4
|
+
// Exporters for multiple formats
|
|
5
|
+
export { HTMLExporter } from './core/exporters/html-exporter';
|
|
6
|
+
export { MarkdownExporter } from './core/exporters/markdown-exporter';
|
|
7
|
+
export { JSONExporter } from './core/exporters/json-exporter';
|
|
8
|
+
|
|
4
9
|
// The main view layer
|
|
5
10
|
export * from './view';
|
|
6
11
|
|