@noirmd/previewer 1.0.1 → 1.1.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/NReditor.cjs +41 -38
- package/dist/NReditor.cjs.map +1 -1
- package/dist/NReditor.js +41 -38
- package/dist/NReditor.js.map +1 -1
- package/dist/core.cjs +464 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +118 -0
- package/dist/core.d.ts +118 -0
- package/dist/core.js +429 -0
- package/dist/core.js.map +1 -0
- package/dist/index.cjs +56 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +120 -73
- package/dist/index.d.ts +120 -73
- package/dist/index.js +48 -37
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +12044 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +225 -0
- package/dist/react.d.ts +225 -0
- package/dist/react.js +12018 -0
- package/dist/react.js.map +1 -0
- package/dist/vanilla.cjs +11844 -0
- package/dist/vanilla.cjs.map +1 -0
- package/dist/vanilla.css +677 -0
- package/dist/vanilla.d.cts +173 -0
- package/dist/vanilla.d.ts +173 -0
- package/dist/vanilla.js +11818 -0
- package/dist/vanilla.js.map +1 -0
- package/dist/vue.cjs +12227 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.cts +389 -0
- package/dist/vue.d.ts +389 -0
- package/dist/vue.js +12202 -0
- package/dist/vue.js.map +1 -0
- package/package.json +45 -14
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic CSSProperties — framework-agnostic equivalent of React.CSSProperties.
|
|
3
|
+
* Used for inline styles on tokens (e.g. images).
|
|
4
|
+
*/
|
|
5
|
+
type CSSProperties = Record<string, string | number>;
|
|
6
|
+
interface HeaderToken {
|
|
7
|
+
type: 'header';
|
|
8
|
+
level: number;
|
|
9
|
+
text: string;
|
|
10
|
+
id: string;
|
|
11
|
+
classes?: string;
|
|
12
|
+
}
|
|
13
|
+
interface ParagraphToken {
|
|
14
|
+
type: 'paragraph';
|
|
15
|
+
content: string;
|
|
16
|
+
align?: 'center' | 'right';
|
|
17
|
+
classes?: string;
|
|
18
|
+
id?: string;
|
|
19
|
+
}
|
|
20
|
+
interface CodeblockToken {
|
|
21
|
+
type: 'codeblock';
|
|
22
|
+
language: string;
|
|
23
|
+
content: string;
|
|
24
|
+
title?: string;
|
|
25
|
+
}
|
|
26
|
+
interface DirectiveToken {
|
|
27
|
+
type: 'directive';
|
|
28
|
+
directiveType: string;
|
|
29
|
+
props: Record<string, string>;
|
|
30
|
+
slots: Record<string, string>;
|
|
31
|
+
scopeId: string;
|
|
32
|
+
}
|
|
33
|
+
interface HtmlToken {
|
|
34
|
+
type: 'html';
|
|
35
|
+
content: string;
|
|
36
|
+
scopeId: string;
|
|
37
|
+
}
|
|
38
|
+
interface HtmlBlockToken {
|
|
39
|
+
type: 'html-block';
|
|
40
|
+
tag: string;
|
|
41
|
+
attrs: string;
|
|
42
|
+
children: Token[];
|
|
43
|
+
}
|
|
44
|
+
interface ImageToken {
|
|
45
|
+
type: 'image';
|
|
46
|
+
alt: string;
|
|
47
|
+
src: string;
|
|
48
|
+
style: CSSProperties;
|
|
49
|
+
}
|
|
50
|
+
interface TableToken {
|
|
51
|
+
type: 'table';
|
|
52
|
+
content: string;
|
|
53
|
+
}
|
|
54
|
+
interface ListToken {
|
|
55
|
+
type: 'list';
|
|
56
|
+
content: string;
|
|
57
|
+
}
|
|
58
|
+
interface BlockquoteToken {
|
|
59
|
+
type: 'blockquote';
|
|
60
|
+
content: string;
|
|
61
|
+
classes?: string;
|
|
62
|
+
id?: string;
|
|
63
|
+
}
|
|
64
|
+
interface HrToken {
|
|
65
|
+
type: 'hr';
|
|
66
|
+
}
|
|
67
|
+
interface TocToken {
|
|
68
|
+
type: 'toc';
|
|
69
|
+
}
|
|
70
|
+
type Token = HeaderToken | ParagraphToken | CodeblockToken | DirectiveToken | HtmlToken | HtmlBlockToken | ImageToken | TableToken | ListToken | BlockquoteToken | HrToken | TocToken;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Render parsed markdown tokens into an HTMLElement.
|
|
74
|
+
*
|
|
75
|
+
* @param tokens - Array of tokens from `parseMarkdown()`
|
|
76
|
+
* @returns The root `<article class="nr-prose">` element
|
|
77
|
+
*/
|
|
78
|
+
declare function renderTokens(tokens: Token[]): HTMLElement;
|
|
79
|
+
/**
|
|
80
|
+
* Convenience: parse markdown string and render directly.
|
|
81
|
+
*/
|
|
82
|
+
declare function renderMarkdownString(markdown: string): HTMLElement;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Render inline markdown text into a DocumentFragment.
|
|
86
|
+
*
|
|
87
|
+
* Supports: bold, italic, bold-italic, strikethrough, code, highlight,
|
|
88
|
+
* spoiler, color text, underline, icons, links, raw HTML tags.
|
|
89
|
+
*/
|
|
90
|
+
declare function renderInline(text: string): DocumentFragment;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Create a Material Symbols icon element.
|
|
94
|
+
*/
|
|
95
|
+
declare function createIcon(iconName: string, extraClasses?: string): HTMLElement;
|
|
96
|
+
/**
|
|
97
|
+
* Create a syntax-highlighted code block with copy button.
|
|
98
|
+
*/
|
|
99
|
+
declare function createCodeBlock(code: string, language: string, title?: string): HTMLElement;
|
|
100
|
+
/**
|
|
101
|
+
* Create an admonition (alert) box.
|
|
102
|
+
* Content should be appended by the caller.
|
|
103
|
+
*/
|
|
104
|
+
declare function createAdmonition(type: string, title?: string, icon?: string): HTMLElement;
|
|
105
|
+
/**
|
|
106
|
+
* Create a native <details> collapsible section.
|
|
107
|
+
* Content should be appended to the body div.
|
|
108
|
+
*/
|
|
109
|
+
declare function createDetails(title: string, icon?: string, defaultOpen?: boolean): HTMLElement;
|
|
110
|
+
/**
|
|
111
|
+
* Create a native <dialog> modal.
|
|
112
|
+
* Content should be appended to the body div.
|
|
113
|
+
*/
|
|
114
|
+
declare function createModal(title: string): HTMLDialogElement;
|
|
115
|
+
/**
|
|
116
|
+
* Render a pipe-delimited markdown table into an HTML table element.
|
|
117
|
+
* Returns the outer wrapper div.
|
|
118
|
+
*/
|
|
119
|
+
declare function createTable(content: string, renderInline: (text: string) => DocumentFragment): HTMLElement;
|
|
120
|
+
/**
|
|
121
|
+
* Render a markdown list (ordered or unordered) into HTML.
|
|
122
|
+
*/
|
|
123
|
+
declare function createList(content: string, renderInline: (text: string) => DocumentFragment): HTMLElement;
|
|
124
|
+
interface TocHeader {
|
|
125
|
+
level: number;
|
|
126
|
+
text: string;
|
|
127
|
+
id: string;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Create a table of contents from an array of headers.
|
|
131
|
+
*/
|
|
132
|
+
declare function createTOC(headers: TocHeader[], renderInline: (text: string) => DocumentFragment): HTMLElement;
|
|
133
|
+
/**
|
|
134
|
+
* Create a blockquote element.
|
|
135
|
+
*/
|
|
136
|
+
declare function createBlockquote(content: string, classes: string | undefined, renderInline: (text: string) => DocumentFragment): HTMLElement;
|
|
137
|
+
|
|
138
|
+
interface VanillaRenderContext {
|
|
139
|
+
/** Parse markdown string into tokens */
|
|
140
|
+
parseMarkdown: (md: string) => Token[];
|
|
141
|
+
/** Render tokens into an HTMLElement */
|
|
142
|
+
renderElements: (tokens: Token[]) => HTMLElement;
|
|
143
|
+
/** Render inline text into a DocumentFragment */
|
|
144
|
+
renderInline: (text: string) => DocumentFragment;
|
|
145
|
+
/** Parse markdown string and render into an HTMLElement */
|
|
146
|
+
renderMarkdown: (md: string) => HTMLElement;
|
|
147
|
+
}
|
|
148
|
+
interface DirectiveProps {
|
|
149
|
+
/** The directive type string */
|
|
150
|
+
directiveType: string;
|
|
151
|
+
/** Parsed key="value" attributes */
|
|
152
|
+
props: Record<string, string>;
|
|
153
|
+
/** Named slots → raw content strings */
|
|
154
|
+
slots: Record<string, string>;
|
|
155
|
+
/** Render a named slot as parsed markdown */
|
|
156
|
+
renderSlot: (name: string) => DocumentFragment;
|
|
157
|
+
/** Render context */
|
|
158
|
+
context: VanillaRenderContext;
|
|
159
|
+
/** Position index */
|
|
160
|
+
index: number;
|
|
161
|
+
/** Full parsed AST */
|
|
162
|
+
allElements: Token[];
|
|
163
|
+
/** Extra flags */
|
|
164
|
+
options?: Record<string, any>;
|
|
165
|
+
/** Inline renderer shortcut */
|
|
166
|
+
renderInline: (text: string) => DocumentFragment;
|
|
167
|
+
/** Full markdown renderer shortcut (for complex directives like slide) */
|
|
168
|
+
renderMarkdown?: (md: string) => HTMLElement;
|
|
169
|
+
}
|
|
170
|
+
type DirectiveRendererFn = (props: DirectiveProps) => HTMLElement | DocumentFragment;
|
|
171
|
+
declare const directiveRegistry: Record<string, DirectiveRendererFn>;
|
|
172
|
+
|
|
173
|
+
export { type DirectiveProps, type DirectiveRendererFn, type VanillaRenderContext, createAdmonition, createBlockquote, createCodeBlock, createDetails, createIcon, createList, createModal, createTOC, createTable, directiveRegistry, renderInline, renderMarkdownString, renderTokens };
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic CSSProperties — framework-agnostic equivalent of React.CSSProperties.
|
|
3
|
+
* Used for inline styles on tokens (e.g. images).
|
|
4
|
+
*/
|
|
5
|
+
type CSSProperties = Record<string, string | number>;
|
|
6
|
+
interface HeaderToken {
|
|
7
|
+
type: 'header';
|
|
8
|
+
level: number;
|
|
9
|
+
text: string;
|
|
10
|
+
id: string;
|
|
11
|
+
classes?: string;
|
|
12
|
+
}
|
|
13
|
+
interface ParagraphToken {
|
|
14
|
+
type: 'paragraph';
|
|
15
|
+
content: string;
|
|
16
|
+
align?: 'center' | 'right';
|
|
17
|
+
classes?: string;
|
|
18
|
+
id?: string;
|
|
19
|
+
}
|
|
20
|
+
interface CodeblockToken {
|
|
21
|
+
type: 'codeblock';
|
|
22
|
+
language: string;
|
|
23
|
+
content: string;
|
|
24
|
+
title?: string;
|
|
25
|
+
}
|
|
26
|
+
interface DirectiveToken {
|
|
27
|
+
type: 'directive';
|
|
28
|
+
directiveType: string;
|
|
29
|
+
props: Record<string, string>;
|
|
30
|
+
slots: Record<string, string>;
|
|
31
|
+
scopeId: string;
|
|
32
|
+
}
|
|
33
|
+
interface HtmlToken {
|
|
34
|
+
type: 'html';
|
|
35
|
+
content: string;
|
|
36
|
+
scopeId: string;
|
|
37
|
+
}
|
|
38
|
+
interface HtmlBlockToken {
|
|
39
|
+
type: 'html-block';
|
|
40
|
+
tag: string;
|
|
41
|
+
attrs: string;
|
|
42
|
+
children: Token[];
|
|
43
|
+
}
|
|
44
|
+
interface ImageToken {
|
|
45
|
+
type: 'image';
|
|
46
|
+
alt: string;
|
|
47
|
+
src: string;
|
|
48
|
+
style: CSSProperties;
|
|
49
|
+
}
|
|
50
|
+
interface TableToken {
|
|
51
|
+
type: 'table';
|
|
52
|
+
content: string;
|
|
53
|
+
}
|
|
54
|
+
interface ListToken {
|
|
55
|
+
type: 'list';
|
|
56
|
+
content: string;
|
|
57
|
+
}
|
|
58
|
+
interface BlockquoteToken {
|
|
59
|
+
type: 'blockquote';
|
|
60
|
+
content: string;
|
|
61
|
+
classes?: string;
|
|
62
|
+
id?: string;
|
|
63
|
+
}
|
|
64
|
+
interface HrToken {
|
|
65
|
+
type: 'hr';
|
|
66
|
+
}
|
|
67
|
+
interface TocToken {
|
|
68
|
+
type: 'toc';
|
|
69
|
+
}
|
|
70
|
+
type Token = HeaderToken | ParagraphToken | CodeblockToken | DirectiveToken | HtmlToken | HtmlBlockToken | ImageToken | TableToken | ListToken | BlockquoteToken | HrToken | TocToken;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Render parsed markdown tokens into an HTMLElement.
|
|
74
|
+
*
|
|
75
|
+
* @param tokens - Array of tokens from `parseMarkdown()`
|
|
76
|
+
* @returns The root `<article class="nr-prose">` element
|
|
77
|
+
*/
|
|
78
|
+
declare function renderTokens(tokens: Token[]): HTMLElement;
|
|
79
|
+
/**
|
|
80
|
+
* Convenience: parse markdown string and render directly.
|
|
81
|
+
*/
|
|
82
|
+
declare function renderMarkdownString(markdown: string): HTMLElement;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Render inline markdown text into a DocumentFragment.
|
|
86
|
+
*
|
|
87
|
+
* Supports: bold, italic, bold-italic, strikethrough, code, highlight,
|
|
88
|
+
* spoiler, color text, underline, icons, links, raw HTML tags.
|
|
89
|
+
*/
|
|
90
|
+
declare function renderInline(text: string): DocumentFragment;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Create a Material Symbols icon element.
|
|
94
|
+
*/
|
|
95
|
+
declare function createIcon(iconName: string, extraClasses?: string): HTMLElement;
|
|
96
|
+
/**
|
|
97
|
+
* Create a syntax-highlighted code block with copy button.
|
|
98
|
+
*/
|
|
99
|
+
declare function createCodeBlock(code: string, language: string, title?: string): HTMLElement;
|
|
100
|
+
/**
|
|
101
|
+
* Create an admonition (alert) box.
|
|
102
|
+
* Content should be appended by the caller.
|
|
103
|
+
*/
|
|
104
|
+
declare function createAdmonition(type: string, title?: string, icon?: string): HTMLElement;
|
|
105
|
+
/**
|
|
106
|
+
* Create a native <details> collapsible section.
|
|
107
|
+
* Content should be appended to the body div.
|
|
108
|
+
*/
|
|
109
|
+
declare function createDetails(title: string, icon?: string, defaultOpen?: boolean): HTMLElement;
|
|
110
|
+
/**
|
|
111
|
+
* Create a native <dialog> modal.
|
|
112
|
+
* Content should be appended to the body div.
|
|
113
|
+
*/
|
|
114
|
+
declare function createModal(title: string): HTMLDialogElement;
|
|
115
|
+
/**
|
|
116
|
+
* Render a pipe-delimited markdown table into an HTML table element.
|
|
117
|
+
* Returns the outer wrapper div.
|
|
118
|
+
*/
|
|
119
|
+
declare function createTable(content: string, renderInline: (text: string) => DocumentFragment): HTMLElement;
|
|
120
|
+
/**
|
|
121
|
+
* Render a markdown list (ordered or unordered) into HTML.
|
|
122
|
+
*/
|
|
123
|
+
declare function createList(content: string, renderInline: (text: string) => DocumentFragment): HTMLElement;
|
|
124
|
+
interface TocHeader {
|
|
125
|
+
level: number;
|
|
126
|
+
text: string;
|
|
127
|
+
id: string;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Create a table of contents from an array of headers.
|
|
131
|
+
*/
|
|
132
|
+
declare function createTOC(headers: TocHeader[], renderInline: (text: string) => DocumentFragment): HTMLElement;
|
|
133
|
+
/**
|
|
134
|
+
* Create a blockquote element.
|
|
135
|
+
*/
|
|
136
|
+
declare function createBlockquote(content: string, classes: string | undefined, renderInline: (text: string) => DocumentFragment): HTMLElement;
|
|
137
|
+
|
|
138
|
+
interface VanillaRenderContext {
|
|
139
|
+
/** Parse markdown string into tokens */
|
|
140
|
+
parseMarkdown: (md: string) => Token[];
|
|
141
|
+
/** Render tokens into an HTMLElement */
|
|
142
|
+
renderElements: (tokens: Token[]) => HTMLElement;
|
|
143
|
+
/** Render inline text into a DocumentFragment */
|
|
144
|
+
renderInline: (text: string) => DocumentFragment;
|
|
145
|
+
/** Parse markdown string and render into an HTMLElement */
|
|
146
|
+
renderMarkdown: (md: string) => HTMLElement;
|
|
147
|
+
}
|
|
148
|
+
interface DirectiveProps {
|
|
149
|
+
/** The directive type string */
|
|
150
|
+
directiveType: string;
|
|
151
|
+
/** Parsed key="value" attributes */
|
|
152
|
+
props: Record<string, string>;
|
|
153
|
+
/** Named slots → raw content strings */
|
|
154
|
+
slots: Record<string, string>;
|
|
155
|
+
/** Render a named slot as parsed markdown */
|
|
156
|
+
renderSlot: (name: string) => DocumentFragment;
|
|
157
|
+
/** Render context */
|
|
158
|
+
context: VanillaRenderContext;
|
|
159
|
+
/** Position index */
|
|
160
|
+
index: number;
|
|
161
|
+
/** Full parsed AST */
|
|
162
|
+
allElements: Token[];
|
|
163
|
+
/** Extra flags */
|
|
164
|
+
options?: Record<string, any>;
|
|
165
|
+
/** Inline renderer shortcut */
|
|
166
|
+
renderInline: (text: string) => DocumentFragment;
|
|
167
|
+
/** Full markdown renderer shortcut (for complex directives like slide) */
|
|
168
|
+
renderMarkdown?: (md: string) => HTMLElement;
|
|
169
|
+
}
|
|
170
|
+
type DirectiveRendererFn = (props: DirectiveProps) => HTMLElement | DocumentFragment;
|
|
171
|
+
declare const directiveRegistry: Record<string, DirectiveRendererFn>;
|
|
172
|
+
|
|
173
|
+
export { type DirectiveProps, type DirectiveRendererFn, type VanillaRenderContext, createAdmonition, createBlockquote, createCodeBlock, createDetails, createIcon, createList, createModal, createTOC, createTable, directiveRegistry, renderInline, renderMarkdownString, renderTokens };
|