draftly 0.1.0-alpha.0 → 1.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +346 -0
- package/dist/chunk-2B3A3VSQ.cjs +3382 -0
- package/dist/chunk-2B3A3VSQ.cjs.map +1 -0
- package/dist/chunk-72ZYRGRT.cjs +399 -0
- package/dist/chunk-72ZYRGRT.cjs.map +1 -0
- package/dist/chunk-CG4M4TC7.js +392 -0
- package/dist/chunk-CG4M4TC7.js.map +1 -0
- package/dist/chunk-DFQYXFOP.js +86 -0
- package/dist/chunk-DFQYXFOP.js.map +1 -0
- package/dist/chunk-HPSMS2WB.js +182 -0
- package/dist/chunk-HPSMS2WB.js.map +1 -0
- package/dist/chunk-KBQDZ5IW.cjs +192 -0
- package/dist/chunk-KBQDZ5IW.cjs.map +1 -0
- package/dist/chunk-KDEDLC3D.cjs +93 -0
- package/dist/chunk-KDEDLC3D.cjs.map +1 -0
- package/dist/chunk-N3WL3XPB.js +3360 -0
- package/dist/chunk-N3WL3XPB.js.map +1 -0
- package/dist/draftly-BLnx3uGX.d.cts +293 -0
- package/dist/draftly-BLnx3uGX.d.ts +293 -0
- package/dist/editor/index.cjs +57 -0
- package/dist/editor/index.cjs.map +1 -0
- package/dist/editor/index.d.cts +15 -0
- package/dist/editor/index.d.ts +15 -0
- package/dist/editor/index.js +4 -0
- package/dist/editor/index.js.map +1 -0
- package/dist/index.cjs +120 -1129
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -257
- package/dist/index.d.ts +9 -257
- package/dist/index.js +4 -1126
- package/dist/index.js.map +1 -1
- package/dist/plugins/index.cjs +66 -0
- package/dist/plugins/index.cjs.map +1 -0
- package/dist/plugins/index.d.cts +515 -0
- package/dist/plugins/index.d.ts +515 -0
- package/dist/plugins/index.js +5 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/preview/index.cjs +29 -0
- package/dist/preview/index.cjs.map +1 -0
- package/dist/preview/index.d.cts +143 -0
- package/dist/preview/index.d.ts +143 -0
- package/dist/preview/index.js +4 -0
- package/dist/preview/index.js.map +1 -0
- package/package.json +22 -1
- package/src/{draftly.ts → editor/draftly.ts} +28 -27
- package/src/editor/index.ts +5 -0
- package/src/{plugin.ts → editor/plugin.ts} +62 -34
- package/src/editor/theme.ts +62 -0
- package/src/editor/utils.ts +143 -0
- package/src/{view-plugin.ts → editor/view-plugin.ts} +25 -140
- package/src/index.ts +4 -7
- package/src/plugins/code-plugin.ts +1119 -0
- package/src/plugins/heading-plugin.ts +108 -74
- package/src/plugins/hr-plugin.ts +102 -0
- package/src/plugins/html-plugin.ts +59 -53
- package/src/plugins/image-plugin.ts +447 -0
- package/src/plugins/index.ts +57 -0
- package/src/plugins/inline-plugin.ts +178 -39
- package/src/plugins/link-plugin.ts +509 -0
- package/src/plugins/list-plugin.ts +492 -211
- package/src/plugins/math-plugin.ts +514 -0
- package/src/plugins/mermaid-plugin.ts +500 -0
- package/src/plugins/paragraph-plugin.ts +38 -0
- package/src/plugins/quote-plugin.ts +146 -0
- package/src/preview/context.ts +38 -0
- package/src/preview/css-generator.ts +51 -0
- package/src/preview/default-renderers.ts +29 -0
- package/src/preview/index.ts +20 -0
- package/src/preview/preview.ts +40 -0
- package/src/preview/renderer.ts +157 -0
- package/src/preview/types.ts +72 -0
- package/src/plugins/plugins.ts +0 -9
- package/src/theme.ts +0 -86
- package/src/utils.ts +0 -21
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
import { d as DraftlyPlugin, T as ThemeEnum, f as ThemeStyle, a as DecorationPlugin, D as DecorationContext } from '../draftly-BLnx3uGX.js';
|
|
2
|
+
import { SyntaxNode } from '@lezer/common';
|
|
3
|
+
import { KeyBinding } from '@codemirror/view';
|
|
4
|
+
import { MarkdownConfig } from '@lezer/markdown';
|
|
5
|
+
import '@codemirror/state';
|
|
6
|
+
import 'style-mod';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* ParagraphPlugin - Adds top and bottom padding to paragraphs in preview
|
|
10
|
+
*
|
|
11
|
+
* Applies visual spacing to markdown paragraphs for better readability
|
|
12
|
+
*/
|
|
13
|
+
declare class ParagraphPlugin extends DraftlyPlugin {
|
|
14
|
+
readonly name = "paragraph";
|
|
15
|
+
readonly version = "1.0.0";
|
|
16
|
+
readonly requiredNodes: readonly ["Paragraph"];
|
|
17
|
+
/**
|
|
18
|
+
* Plugin theme for preview styling
|
|
19
|
+
*/
|
|
20
|
+
get theme(): (theme: ThemeEnum) => ThemeStyle;
|
|
21
|
+
renderToHTML(node: SyntaxNode, children: string): string | null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* HeadingPlugin - Decorates markdown headings
|
|
26
|
+
*
|
|
27
|
+
* Adds visual styling to ATX headings (# through ######)
|
|
28
|
+
* - Line decorations for the entire heading line
|
|
29
|
+
* - Mark decorations for heading content
|
|
30
|
+
* - Hides # markers when cursor is not in the heading
|
|
31
|
+
*/
|
|
32
|
+
declare class HeadingPlugin extends DecorationPlugin {
|
|
33
|
+
readonly name = "heading";
|
|
34
|
+
readonly version = "1.0.0";
|
|
35
|
+
decorationPriority: number;
|
|
36
|
+
readonly requiredNodes: readonly ["ATXHeading1", "ATXHeading2", "ATXHeading3", "ATXHeading4", "ATXHeading5", "ATXHeading6", "HeaderMark"];
|
|
37
|
+
/**
|
|
38
|
+
* Constructor - calls super constructor
|
|
39
|
+
*/
|
|
40
|
+
constructor();
|
|
41
|
+
/**
|
|
42
|
+
* Plugin theme
|
|
43
|
+
*/
|
|
44
|
+
get theme(): (theme: ThemeEnum) => ThemeStyle;
|
|
45
|
+
/**
|
|
46
|
+
* Build heading decorations by iterating the syntax tree
|
|
47
|
+
*/
|
|
48
|
+
buildDecorations(ctx: DecorationContext): void;
|
|
49
|
+
renderToHTML(node: SyntaxNode, children: string): string | null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* InlinePlugin - Decorates inline markdown formatting
|
|
54
|
+
*
|
|
55
|
+
* Adds visual styling to inline elements:
|
|
56
|
+
* - Emphasis (italic) - *text* or _text_
|
|
57
|
+
* - Strong (bold) - **text** or __text__
|
|
58
|
+
* - Strikethrough - ~~text~~
|
|
59
|
+
* - Subscript - ~text~
|
|
60
|
+
* - Superscript - ^text^
|
|
61
|
+
* - Highlight - ==text==
|
|
62
|
+
*
|
|
63
|
+
* Hides formatting markers when cursor is not in the element
|
|
64
|
+
*/
|
|
65
|
+
declare class InlinePlugin extends DecorationPlugin {
|
|
66
|
+
readonly name = "inline";
|
|
67
|
+
readonly version = "1.0.0";
|
|
68
|
+
decorationPriority: number;
|
|
69
|
+
readonly requiredNodes: readonly ["Emphasis", "StrongEmphasis", "Strikethrough", "Subscript", "Superscript", "Highlight", "EmphasisMark", "StrikethroughMark", "SubscriptMark", "SuperscriptMark", "HighlightMark"];
|
|
70
|
+
marks: string[];
|
|
71
|
+
constructor();
|
|
72
|
+
/**
|
|
73
|
+
* Plugin theme
|
|
74
|
+
*/
|
|
75
|
+
get theme(): (theme: ThemeEnum) => ThemeStyle;
|
|
76
|
+
/**
|
|
77
|
+
* Keyboard shortcuts for inline formatting
|
|
78
|
+
*/
|
|
79
|
+
getKeymap(): KeyBinding[];
|
|
80
|
+
/**
|
|
81
|
+
* Return markdown parser extensions for highlight syntax (==text==)
|
|
82
|
+
*/
|
|
83
|
+
getMarkdownConfig(): MarkdownConfig;
|
|
84
|
+
/**
|
|
85
|
+
* Build inline decorations by iterating the syntax tree
|
|
86
|
+
*/
|
|
87
|
+
buildDecorations(ctx: DecorationContext): void;
|
|
88
|
+
/**
|
|
89
|
+
* Get the marker node names for a given inline type
|
|
90
|
+
*/
|
|
91
|
+
private getMarkerNames;
|
|
92
|
+
renderToHTML(node: SyntaxNode, children: string): string | null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* LinkPlugin - Decorates and provides interactivity for markdown links
|
|
97
|
+
*
|
|
98
|
+
* Supports the full link syntax: [text](url) and [text](url "title")
|
|
99
|
+
* - Click: reveals raw markdown (selects/focuses the link syntax)
|
|
100
|
+
* - Ctrl+Click: opens the link URL in a new browser tab
|
|
101
|
+
* - Hover: shows tooltip with the link URL
|
|
102
|
+
* - Hides the markdown syntax when cursor is not in range
|
|
103
|
+
* - Shows raw markdown when cursor is within the link range
|
|
104
|
+
*/
|
|
105
|
+
declare class LinkPlugin extends DecorationPlugin {
|
|
106
|
+
readonly name = "link";
|
|
107
|
+
readonly version = "1.0.0";
|
|
108
|
+
decorationPriority: number;
|
|
109
|
+
readonly requiredNodes: readonly ["Link"];
|
|
110
|
+
constructor();
|
|
111
|
+
/**
|
|
112
|
+
* Plugin theme
|
|
113
|
+
*/
|
|
114
|
+
get theme(): (theme: ThemeEnum) => ThemeStyle;
|
|
115
|
+
/**
|
|
116
|
+
* Keyboard shortcuts for link formatting
|
|
117
|
+
*/
|
|
118
|
+
getKeymap(): KeyBinding[];
|
|
119
|
+
/**
|
|
120
|
+
* URL regex pattern
|
|
121
|
+
*/
|
|
122
|
+
private readonly urlPattern;
|
|
123
|
+
/**
|
|
124
|
+
* Toggle link on selection
|
|
125
|
+
* - If text is selected and is a URL: [](url) with cursor in brackets
|
|
126
|
+
* - If text is selected (not URL): [text]() with cursor in parentheses
|
|
127
|
+
* - If nothing selected: []() with cursor in brackets
|
|
128
|
+
* - If already a link: remove syntax, leave plain text
|
|
129
|
+
*/
|
|
130
|
+
private toggleLink;
|
|
131
|
+
buildDecorations(ctx: DecorationContext): void;
|
|
132
|
+
/**
|
|
133
|
+
* Decorate raw link markdown when cursor is in range
|
|
134
|
+
*/
|
|
135
|
+
private decorateRawLink;
|
|
136
|
+
/**
|
|
137
|
+
* Render link to HTML for preview mode
|
|
138
|
+
*/
|
|
139
|
+
renderToHTML(node: SyntaxNode, _children: string, ctx: {
|
|
140
|
+
sliceDoc(from: number, to: number): string;
|
|
141
|
+
sanitize(html: string): string;
|
|
142
|
+
}): string | null;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Decorates markdown lists with custom styling.
|
|
147
|
+
*
|
|
148
|
+
* Supports:
|
|
149
|
+
* - **Unordered lists** — Replaces `*`, `-`, `+` markers with styled bullets
|
|
150
|
+
* - **Ordered lists** — Styles numbered markers (`1.`, `2.`, etc.)
|
|
151
|
+
* - **Task lists** — Renders `[ ]`/`[x]` as interactive checkboxes
|
|
152
|
+
*/
|
|
153
|
+
declare class ListPlugin extends DecorationPlugin {
|
|
154
|
+
readonly name = "list";
|
|
155
|
+
readonly version = "1.0.0";
|
|
156
|
+
decorationPriority: number;
|
|
157
|
+
readonly requiredNodes: readonly ["BulletList", "OrderedList", "ListItem", "ListMark", "Task", "TaskMarker"];
|
|
158
|
+
get theme(): (theme: ThemeEnum) => ThemeStyle;
|
|
159
|
+
/**
|
|
160
|
+
* Keyboard shortcuts for list formatting
|
|
161
|
+
*/
|
|
162
|
+
getKeymap(): KeyBinding[];
|
|
163
|
+
/**
|
|
164
|
+
* Toggle list marker on current line or selected lines
|
|
165
|
+
*/
|
|
166
|
+
private toggleListOnLines;
|
|
167
|
+
buildDecorations(ctx: DecorationContext): void;
|
|
168
|
+
/** Add line decoration for list items with nesting depth */
|
|
169
|
+
private decorateListItem;
|
|
170
|
+
/** Check if a ListItem node has a Task child */
|
|
171
|
+
private hasTaskChild;
|
|
172
|
+
/** Decorate list markers (bullets for UL, numbers for OL) */
|
|
173
|
+
private decorateListMark;
|
|
174
|
+
/** Decorate task markers - show checkbox widget or raw text based on cursor */
|
|
175
|
+
private decorateTaskMarker;
|
|
176
|
+
/** Render list nodes to HTML */
|
|
177
|
+
renderToHTML(node: SyntaxNode, children: string, ctx: {
|
|
178
|
+
sliceDoc(from: number, to: number): string;
|
|
179
|
+
sanitize(html: string): string;
|
|
180
|
+
}): string | null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* HTMLPlugin - Decorates and Renders HTML in markdown
|
|
185
|
+
*/
|
|
186
|
+
declare class HTMLPlugin extends DecorationPlugin {
|
|
187
|
+
readonly name = "html";
|
|
188
|
+
readonly version = "1.0.0";
|
|
189
|
+
decorationPriority: number;
|
|
190
|
+
constructor();
|
|
191
|
+
/**
|
|
192
|
+
* Plugin theme
|
|
193
|
+
*/
|
|
194
|
+
get theme(): (theme: ThemeEnum) => ThemeStyle;
|
|
195
|
+
buildDecorations(ctx: DecorationContext): void;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* ImagePlugin - Decorates and renders images in markdown
|
|
200
|
+
*
|
|
201
|
+
* Supports the full image syntax: 
|
|
202
|
+
* - Shows image widget below the node when cursor is not in range
|
|
203
|
+
* - Hides the markdown syntax when cursor is not in range
|
|
204
|
+
* - Shows raw markdown when cursor is in the image syntax
|
|
205
|
+
* - Uses figure/figcaption for semantic HTML with accessibility attributes
|
|
206
|
+
*/
|
|
207
|
+
declare class ImagePlugin extends DecorationPlugin {
|
|
208
|
+
readonly name = "image";
|
|
209
|
+
readonly version = "1.0.0";
|
|
210
|
+
decorationPriority: number;
|
|
211
|
+
readonly requiredNodes: readonly ["Image"];
|
|
212
|
+
constructor();
|
|
213
|
+
/**
|
|
214
|
+
* Plugin theme
|
|
215
|
+
*/
|
|
216
|
+
get theme(): (theme: ThemeEnum) => ThemeStyle;
|
|
217
|
+
/**
|
|
218
|
+
* Keyboard shortcuts for image formatting
|
|
219
|
+
*/
|
|
220
|
+
getKeymap(): KeyBinding[];
|
|
221
|
+
/**
|
|
222
|
+
* URL regex pattern
|
|
223
|
+
*/
|
|
224
|
+
private readonly urlPattern;
|
|
225
|
+
/**
|
|
226
|
+
* Toggle image on selection
|
|
227
|
+
* - If text selected and is a URL:  with cursor in brackets
|
|
228
|
+
* - If text selected (not URL): ![text]() with cursor in parentheses
|
|
229
|
+
* - If nothing selected: ![Alt Text]() with cursor in parentheses
|
|
230
|
+
* - If already an image: remove syntax, leave just the URL
|
|
231
|
+
*/
|
|
232
|
+
private toggleImage;
|
|
233
|
+
buildDecorations(ctx: DecorationContext): void;
|
|
234
|
+
/**
|
|
235
|
+
* Decorate raw image markdown when cursor is in range
|
|
236
|
+
*/
|
|
237
|
+
private decorateRawImage;
|
|
238
|
+
/**
|
|
239
|
+
* Render image to HTML for preview mode using figure/figcaption
|
|
240
|
+
*/
|
|
241
|
+
renderToHTML(node: SyntaxNode, _children: string, ctx: {
|
|
242
|
+
sliceDoc(from: number, to: number): string;
|
|
243
|
+
sanitize(html: string): string;
|
|
244
|
+
}): string | null;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* MathPlugin - Renders LaTeX math expressions using KaTeX
|
|
249
|
+
*
|
|
250
|
+
* Supports:
|
|
251
|
+
* - Inline math: $E = mc^2$
|
|
252
|
+
* - Block math (display mode):
|
|
253
|
+
* $$
|
|
254
|
+
* \int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}
|
|
255
|
+
* $$
|
|
256
|
+
*
|
|
257
|
+
* Behavior:
|
|
258
|
+
* - Inline math: Show rendered output when cursor outside, raw LaTeX when inside
|
|
259
|
+
* - Block math: Always show rendered output below, hide raw when cursor outside (like ImagePlugin)
|
|
260
|
+
*/
|
|
261
|
+
declare class MathPlugin extends DecorationPlugin {
|
|
262
|
+
readonly name = "math";
|
|
263
|
+
readonly version = "1.0.0";
|
|
264
|
+
decorationPriority: number;
|
|
265
|
+
readonly requiredNodes: readonly ["InlineMath", "MathBlock", "InlineMathMark", "MathBlockMark"];
|
|
266
|
+
constructor();
|
|
267
|
+
/**
|
|
268
|
+
* Plugin theme
|
|
269
|
+
*/
|
|
270
|
+
get theme(): (theme: ThemeEnum) => ThemeStyle;
|
|
271
|
+
/**
|
|
272
|
+
* Return markdown parser extensions for math syntax
|
|
273
|
+
*/
|
|
274
|
+
getMarkdownConfig(): MarkdownConfig;
|
|
275
|
+
/**
|
|
276
|
+
* Build decorations for math expressions
|
|
277
|
+
*/
|
|
278
|
+
buildDecorations(ctx: DecorationContext): void;
|
|
279
|
+
/**
|
|
280
|
+
* Render math to HTML for preview mode
|
|
281
|
+
*/
|
|
282
|
+
renderToHTML(node: SyntaxNode, _children: string, ctx: {
|
|
283
|
+
sliceDoc(from: number, to: number): string;
|
|
284
|
+
sanitize(html: string): string;
|
|
285
|
+
}): string | null;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* MermaidPlugin - Renders mermaid diagrams in the editor
|
|
290
|
+
*
|
|
291
|
+
* Supports block mermaid syntax:
|
|
292
|
+
* ```mermaid
|
|
293
|
+
* graph TD
|
|
294
|
+
* A --> B
|
|
295
|
+
* ```
|
|
296
|
+
*
|
|
297
|
+
* Behavior:
|
|
298
|
+
* - Always show rendered diagram below the block
|
|
299
|
+
* - Hide raw definition when cursor is outside the block
|
|
300
|
+
* - Show raw definition with styled markers when cursor is inside
|
|
301
|
+
*/
|
|
302
|
+
declare class MermaidPlugin extends DecorationPlugin {
|
|
303
|
+
readonly name = "mermaid";
|
|
304
|
+
readonly version = "1.0.0";
|
|
305
|
+
decorationPriority: number;
|
|
306
|
+
readonly requiredNodes: readonly ["MermaidBlock", "MermaidBlockMark"];
|
|
307
|
+
constructor();
|
|
308
|
+
/**
|
|
309
|
+
* Plugin theme
|
|
310
|
+
*/
|
|
311
|
+
get theme(): (theme: ThemeEnum) => ThemeStyle;
|
|
312
|
+
/**
|
|
313
|
+
* Return markdown parser extensions for mermaid syntax
|
|
314
|
+
*/
|
|
315
|
+
getMarkdownConfig(): MarkdownConfig;
|
|
316
|
+
/**
|
|
317
|
+
* Build decorations for mermaid blocks
|
|
318
|
+
*/
|
|
319
|
+
buildDecorations(ctx: DecorationContext): void;
|
|
320
|
+
/**
|
|
321
|
+
* Render mermaid to HTML for preview mode
|
|
322
|
+
*
|
|
323
|
+
* Renders the actual mermaid diagram to SVG HTML
|
|
324
|
+
*/
|
|
325
|
+
renderToHTML(node: SyntaxNode, _children: string, ctx: {
|
|
326
|
+
sliceDoc(from: number, to: number): string;
|
|
327
|
+
sanitize(html: string): string;
|
|
328
|
+
}): Promise<string | null>;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Text highlight definition
|
|
333
|
+
* Matches text or regex patterns with optional instance selection
|
|
334
|
+
*/
|
|
335
|
+
interface TextHighlight {
|
|
336
|
+
/** The pattern to match (regex without slashes) */
|
|
337
|
+
pattern: string;
|
|
338
|
+
/** Specific instances to highlight (e.g., [3,5] or range [3,4,5]) */
|
|
339
|
+
instances?: number[];
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Properties extracted from CodeInfo string
|
|
343
|
+
*
|
|
344
|
+
* Example: ```tsx line-numbers{5} title="hello.tsx" caption="Example" copy {2-4,5} /Hello/3-5
|
|
345
|
+
*/
|
|
346
|
+
interface CodeBlockProperties {
|
|
347
|
+
/** Language identifier (first token) */
|
|
348
|
+
language: string;
|
|
349
|
+
/** Show line numbers, optionally starting from a specific number */
|
|
350
|
+
lineNumbers?: number | boolean;
|
|
351
|
+
/** Title to display */
|
|
352
|
+
title?: string;
|
|
353
|
+
/** Caption to display */
|
|
354
|
+
caption?: string;
|
|
355
|
+
/** Show copy button */
|
|
356
|
+
copy?: boolean;
|
|
357
|
+
/** Lines to highlight (e.g., [2,3,4,5,9]) */
|
|
358
|
+
highlightLines?: number[];
|
|
359
|
+
/** Text patterns to highlight with optional instance selection */
|
|
360
|
+
highlightText?: TextHighlight[];
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* CodePlugin - Handles inline code and fenced code blocks.
|
|
364
|
+
*
|
|
365
|
+
* **Inline code:** `code`
|
|
366
|
+
* Hides backticks when cursor is not in range.
|
|
367
|
+
*
|
|
368
|
+
* **Fenced code blocks:**
|
|
369
|
+
* Supports syntax highlighting, line numbers, line/text highlighting,
|
|
370
|
+
* title, caption, and copy button via CodeInfo properties.
|
|
371
|
+
*
|
|
372
|
+
* @example
|
|
373
|
+
* ```tsx line-numbers{5} title="example.tsx" {2-4} /pattern/
|
|
374
|
+
* const x = 1;
|
|
375
|
+
* ```
|
|
376
|
+
*/
|
|
377
|
+
declare class CodePlugin extends DecorationPlugin {
|
|
378
|
+
readonly name = "code";
|
|
379
|
+
readonly version = "1.0.0";
|
|
380
|
+
decorationPriority: number;
|
|
381
|
+
readonly requiredNodes: readonly ["InlineCode", "FencedCode", "CodeMark", "CodeInfo", "CodeText"];
|
|
382
|
+
/**
|
|
383
|
+
* Plugin theme
|
|
384
|
+
*/
|
|
385
|
+
get theme(): (theme: ThemeEnum) => ThemeStyle;
|
|
386
|
+
/**
|
|
387
|
+
* Keyboard shortcuts for code formatting
|
|
388
|
+
*/
|
|
389
|
+
getKeymap(): KeyBinding[];
|
|
390
|
+
/**
|
|
391
|
+
* Toggle code block on current line or selected lines
|
|
392
|
+
*/
|
|
393
|
+
private toggleCodeBlock;
|
|
394
|
+
/**
|
|
395
|
+
* Parse CodeInfo string into structured properties
|
|
396
|
+
*
|
|
397
|
+
* @param codeInfo - The raw CodeInfo string (e.g., "tsx line-numbers{5} title=\"hello.tsx\" copy {2-4,5} /Hello/3-5")
|
|
398
|
+
* @returns Parsed CodeBlockProperties object
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
* ```typescript
|
|
402
|
+
* parseCodeInfo("tsx line-numbers{5} title=\"hello.tsx\" copy {2-4,5} /Hello/3-5")
|
|
403
|
+
* ```
|
|
404
|
+
*
|
|
405
|
+
* Returns:
|
|
406
|
+
* ```json
|
|
407
|
+
* {
|
|
408
|
+
* language: "tsx",
|
|
409
|
+
* lineNumbers: 5,
|
|
410
|
+
* title: "hello.tsx",
|
|
411
|
+
* copy: true,
|
|
412
|
+
* highlightLines: [2,3,4,5],
|
|
413
|
+
* highlightText: [{ pattern: "Hello", instances: [3,4,5] }]
|
|
414
|
+
* }
|
|
415
|
+
* ```
|
|
416
|
+
*/
|
|
417
|
+
parseCodeInfo(codeInfo: string): CodeBlockProperties;
|
|
418
|
+
/**
|
|
419
|
+
* Build decorations for inline code and fenced code blocks.
|
|
420
|
+
* Handles line numbers, highlights, header/caption widgets, and fence visibility.
|
|
421
|
+
*/
|
|
422
|
+
buildDecorations(ctx: DecorationContext): void;
|
|
423
|
+
/**
|
|
424
|
+
* Render code elements to HTML for static preview.
|
|
425
|
+
* Applies syntax highlighting using @lezer/highlight.
|
|
426
|
+
*/
|
|
427
|
+
renderToHTML(node: SyntaxNode, children: string, ctx: {
|
|
428
|
+
sliceDoc(from: number, to: number): string;
|
|
429
|
+
sanitize(html: string): string;
|
|
430
|
+
}): string | null;
|
|
431
|
+
/**
|
|
432
|
+
* Highlight a single line of code using the language's Lezer parser.
|
|
433
|
+
* Falls back to sanitized plain text if the language is not supported.
|
|
434
|
+
*/
|
|
435
|
+
private highlightCodeLine;
|
|
436
|
+
/**
|
|
437
|
+
* Apply text highlights (regex patterns) to already syntax-highlighted HTML.
|
|
438
|
+
* Wraps matched patterns in `<mark>` elements.
|
|
439
|
+
*/
|
|
440
|
+
private applyTextHighlights;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* QuotePlugin - Decorates markdown blockquotes
|
|
445
|
+
*
|
|
446
|
+
* Adds visual styling to blockquotes (> prefixed lines)
|
|
447
|
+
* - Line decorations for indicating quote blocks with a left border
|
|
448
|
+
* - Mark decorations for quote content
|
|
449
|
+
* - Hides > markers when cursor is not in the blockquote
|
|
450
|
+
*/
|
|
451
|
+
declare class QuotePlugin extends DecorationPlugin {
|
|
452
|
+
readonly name = "quote";
|
|
453
|
+
readonly version = "1.0.0";
|
|
454
|
+
decorationPriority: number;
|
|
455
|
+
readonly requiredNodes: readonly ["Blockquote", "QuoteMark"];
|
|
456
|
+
/**
|
|
457
|
+
* Constructor - calls super constructor
|
|
458
|
+
*/
|
|
459
|
+
constructor();
|
|
460
|
+
/**
|
|
461
|
+
* Plugin theme
|
|
462
|
+
*/
|
|
463
|
+
get theme(): (theme: ThemeEnum) => ThemeStyle;
|
|
464
|
+
/**
|
|
465
|
+
* Build blockquote decorations by iterating the syntax tree
|
|
466
|
+
*/
|
|
467
|
+
buildDecorations(ctx: DecorationContext): void;
|
|
468
|
+
/**
|
|
469
|
+
* Recursively find and hide quote marks
|
|
470
|
+
*/
|
|
471
|
+
private hideQuoteMarks;
|
|
472
|
+
renderToHTML(node: SyntaxNode, children: string): string | null;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* HRPlugin - Decorates markdown horizontal rules
|
|
477
|
+
*
|
|
478
|
+
* Adds visual styling to thematic breaks (---, ***, ___)
|
|
479
|
+
* - Line decoration that renders a centered horizontal line
|
|
480
|
+
* - Hides raw marker characters when the cursor is not on the line
|
|
481
|
+
*/
|
|
482
|
+
declare class HRPlugin extends DecorationPlugin {
|
|
483
|
+
readonly name = "hr";
|
|
484
|
+
readonly version = "1.0.0";
|
|
485
|
+
decorationPriority: number;
|
|
486
|
+
readonly requiredNodes: readonly ["HorizontalRule"];
|
|
487
|
+
/**
|
|
488
|
+
* Constructor - calls super constructor
|
|
489
|
+
*/
|
|
490
|
+
constructor();
|
|
491
|
+
/**
|
|
492
|
+
* Plugin theme
|
|
493
|
+
*/
|
|
494
|
+
get theme(): (theme: ThemeEnum) => ThemeStyle;
|
|
495
|
+
/**
|
|
496
|
+
* Build horizontal rule decorations by iterating the syntax tree
|
|
497
|
+
*/
|
|
498
|
+
buildDecorations(ctx: DecorationContext): void;
|
|
499
|
+
renderToHTML(node: SyntaxNode, _children: string): string | null;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Default plugins
|
|
504
|
+
*
|
|
505
|
+
* This is the set of essential plugins
|
|
506
|
+
*/
|
|
507
|
+
declare const essentialPlugins: DraftlyPlugin[];
|
|
508
|
+
/**
|
|
509
|
+
* All plugins
|
|
510
|
+
*
|
|
511
|
+
* This is the set of all plugins available with draftly
|
|
512
|
+
*/
|
|
513
|
+
declare const allPlugins: DraftlyPlugin[];
|
|
514
|
+
|
|
515
|
+
export { CodePlugin, HRPlugin, HTMLPlugin, HeadingPlugin, ImagePlugin, InlinePlugin, LinkPlugin, ListPlugin, MathPlugin, MermaidPlugin, ParagraphPlugin, QuotePlugin, allPlugins, essentialPlugins };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { CodePlugin, HRPlugin, HTMLPlugin, HeadingPlugin, ImagePlugin, InlinePlugin, LinkPlugin, ListPlugin, MathPlugin, MermaidPlugin, ParagraphPlugin, QuotePlugin, allPlugins, essentialPlugins } from '../chunk-N3WL3XPB.js';
|
|
2
|
+
import '../chunk-CG4M4TC7.js';
|
|
3
|
+
import '../chunk-DFQYXFOP.js';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkKBQDZ5IW_cjs = require('../chunk-KBQDZ5IW.cjs');
|
|
4
|
+
require('../chunk-KDEDLC3D.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, "PreviewRenderer", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunkKBQDZ5IW_cjs.PreviewRenderer; }
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "defaultRenderers", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return chunkKBQDZ5IW_cjs.defaultRenderers; }
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, "escapeHtml", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return chunkKBQDZ5IW_cjs.escapeHtml; }
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports, "generateCSS", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return chunkKBQDZ5IW_cjs.generateCSS; }
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "preview", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return chunkKBQDZ5IW_cjs.preview; }
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=index.cjs.map
|
|
29
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import * as _lezer_markdown from '@lezer/markdown';
|
|
2
|
+
import { MarkdownConfig } from '@lezer/markdown';
|
|
3
|
+
import { d as DraftlyPlugin, T as ThemeEnum } from '../draftly-BLnx3uGX.cjs';
|
|
4
|
+
import { SyntaxNode } from '@lezer/common';
|
|
5
|
+
import '@codemirror/state';
|
|
6
|
+
import '@codemirror/view';
|
|
7
|
+
import 'style-mod';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Context passed to plugin preview methods
|
|
11
|
+
*/
|
|
12
|
+
interface PreviewContext {
|
|
13
|
+
/** Full document text */
|
|
14
|
+
readonly doc: string;
|
|
15
|
+
/** Current theme */
|
|
16
|
+
readonly theme: ThemeEnum;
|
|
17
|
+
/** Slice document text between positions */
|
|
18
|
+
sliceDoc(from: number, to: number): string;
|
|
19
|
+
/** Sanitize HTML content (for HTMLBlock/HTMLTag) */
|
|
20
|
+
sanitize(html: string): string;
|
|
21
|
+
/** Render children of a node to HTML */
|
|
22
|
+
renderChildren(node: SyntaxNode): Promise<string>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Configuration for the preview renderer
|
|
26
|
+
*/
|
|
27
|
+
interface PreviewConfig {
|
|
28
|
+
/** Plugins to use for rendering */
|
|
29
|
+
plugins?: DraftlyPlugin[];
|
|
30
|
+
/** Markdown extensions to use for rendering */
|
|
31
|
+
markdown?: _lezer_markdown.MarkdownConfig[];
|
|
32
|
+
/** CSS class for the wrapper element */
|
|
33
|
+
wrapperClass?: string;
|
|
34
|
+
/** HTML tag for the wrapper element */
|
|
35
|
+
wrapperTag?: "article" | "div" | "section";
|
|
36
|
+
/** Whether to sanitize HTML blocks (default: true) */
|
|
37
|
+
sanitize?: boolean;
|
|
38
|
+
/** Theme to use */
|
|
39
|
+
theme?: ThemeEnum;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Result of CSS generation
|
|
43
|
+
*/
|
|
44
|
+
interface GenerateCSSConfig {
|
|
45
|
+
/** Plugins to extract styles from */
|
|
46
|
+
plugins?: DraftlyPlugin[];
|
|
47
|
+
/** Theme to use */
|
|
48
|
+
theme?: ThemeEnum;
|
|
49
|
+
/** Wrapper class for scoping (default: "draftly-preview") */
|
|
50
|
+
wrapperClass?: string;
|
|
51
|
+
/** Include base styles */
|
|
52
|
+
includeBase?: boolean;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Node renderer function type
|
|
56
|
+
*/
|
|
57
|
+
type NodeRenderer = (node: SyntaxNode, children: string, ctx: PreviewContext) => string;
|
|
58
|
+
/**
|
|
59
|
+
* Map of node names to their renderers
|
|
60
|
+
*/
|
|
61
|
+
type NodeRendererMap = Record<string, NodeRenderer>;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Render markdown to semantic HTML
|
|
65
|
+
*
|
|
66
|
+
* @param markdown - Markdown string to render
|
|
67
|
+
* @param config - Preview configuration
|
|
68
|
+
* @returns HTML string
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* import { preview } from 'draftly/preview';
|
|
73
|
+
* import { HeadingPlugin, ListPlugin } from 'draftly/plugins';
|
|
74
|
+
*
|
|
75
|
+
* const html = preview('# Hello World', {
|
|
76
|
+
* plugins: [new HeadingPlugin(), new ListPlugin()],
|
|
77
|
+
* wrapperClass: 'draftly-preview',
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
declare function preview(markdown: string, config?: PreviewConfig): Promise<string>;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Generate CSS for preview rendering
|
|
85
|
+
*
|
|
86
|
+
* @param config - CSS generation configuration
|
|
87
|
+
* @returns CSS string
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* import { generateCSS } from 'draftly/preview';
|
|
92
|
+
* import { HeadingPlugin, ListPlugin } from 'draftly/plugins';
|
|
93
|
+
*
|
|
94
|
+
* const css = generateCSS({
|
|
95
|
+
* plugins: [new HeadingPlugin(), new ListPlugin()],
|
|
96
|
+
* theme: ThemeEnum.AUTO,
|
|
97
|
+
* includeBase: true,
|
|
98
|
+
* });
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
declare function generateCSS(config?: GenerateCSSConfig): string;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Escape HTML special characters
|
|
105
|
+
*/
|
|
106
|
+
declare function escapeHtml(text: string): string;
|
|
107
|
+
/**
|
|
108
|
+
* Default node renderers for all markdown node types
|
|
109
|
+
*/
|
|
110
|
+
declare const defaultRenderers: NodeRendererMap;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Renderer class that walks the syntax tree and produces HTML
|
|
114
|
+
*/
|
|
115
|
+
declare class PreviewRenderer {
|
|
116
|
+
private doc;
|
|
117
|
+
private theme;
|
|
118
|
+
private plugins;
|
|
119
|
+
private markdown;
|
|
120
|
+
private sanitizeHtml;
|
|
121
|
+
private renderers;
|
|
122
|
+
private ctx;
|
|
123
|
+
private nodeToPlugins;
|
|
124
|
+
constructor(doc: string, plugins: DraftlyPlugin[] | undefined, markdown: MarkdownConfig[], theme?: ThemeEnum, sanitize?: boolean);
|
|
125
|
+
/**
|
|
126
|
+
* Build a map from node names to plugins that handle them
|
|
127
|
+
*/
|
|
128
|
+
private buildNodePluginMap;
|
|
129
|
+
/**
|
|
130
|
+
* Render the document to HTML
|
|
131
|
+
*/
|
|
132
|
+
render(): Promise<string>;
|
|
133
|
+
/**
|
|
134
|
+
* Render a single node to HTML
|
|
135
|
+
*/
|
|
136
|
+
private renderNode;
|
|
137
|
+
/**
|
|
138
|
+
* Render all children of a node, including text between nodes
|
|
139
|
+
*/
|
|
140
|
+
private renderChildren;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export { type GenerateCSSConfig, type NodeRenderer, type NodeRendererMap, type PreviewConfig, type PreviewContext, PreviewRenderer, defaultRenderers, escapeHtml, generateCSS, preview };
|