@aicayzer/inkkit 0.0.18 → 0.1.1
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/NOTICE +4 -2
- package/README.md +11 -7
- package/dist/THIRD-PARTY-NOTICES.txt +2742 -0
- package/dist/chunks/core-CYp5ONPO.js +56519 -0
- package/dist/chunks/highlight-BW9W8PtS.js +14122 -0
- package/dist/core.d.ts +2 -5
- package/dist/core.js +2 -2
- package/dist/editor.d.ts +229 -47
- package/dist/index.js +5 -3
- package/dist/style.css +231 -202
- package/dist/types.d.ts +143 -18
- package/package.json +16 -13
- package/dist/autolink.d.ts +0 -1
- package/dist/autolink.js +0 -18
- package/dist/callouts.d.ts +0 -25
- package/dist/callouts.js +0 -288
- package/dist/clipboard.d.ts +0 -11
- package/dist/clipboard.js +0 -261
- package/dist/code-fences.d.ts +0 -8
- package/dist/code-fences.js +0 -171
- package/dist/comments.d.ts +0 -76
- package/dist/comments.js +0 -545
- package/dist/cursor.d.ts +0 -2
- package/dist/cursor.js +0 -40
- package/dist/decorations.d.ts +0 -2
- package/dist/decorations.js +0 -67
- package/dist/dialect.d.ts +0 -9
- package/dist/dialect.js +0 -446
- package/dist/drop-placement.d.ts +0 -19
- package/dist/drop-placement.js +0 -47
- package/dist/editor.js +0 -2673
- package/dist/files.d.ts +0 -40
- package/dist/files.js +0 -133
- package/dist/highlight.d.ts +0 -1
- package/dist/highlight.js +0 -136
- package/dist/html-import.d.ts +0 -13
- package/dist/html-import.js +0 -477
- package/dist/image-blocks.d.ts +0 -86
- package/dist/image-blocks.js +0 -329
- package/dist/images.d.ts +0 -51
- package/dist/images.js +0 -398
- package/dist/inline-highlight.d.ts +0 -6
- package/dist/inline-highlight.js +0 -112
- package/dist/labels.d.ts +0 -36
- package/dist/labels.js +0 -34
- package/dist/link-safety.d.ts +0 -17
- package/dist/link-safety.js +0 -29
- package/dist/linked-syntax.d.ts +0 -48
- package/dist/linked-syntax.js +0 -320
- package/dist/literals.d.ts +0 -20
- package/dist/literals.js +0 -216
- package/dist/mermaid.d.ts +0 -28
- package/dist/mermaid.js +0 -404
- package/dist/outline.d.ts +0 -22
- package/dist/outline.js +0 -79
- package/dist/paste-html.d.ts +0 -31
- package/dist/paste-html.js +0 -462
- package/dist/paste.d.ts +0 -33
- package/dist/paste.js +0 -591
- package/dist/portable-files.d.ts +0 -10
- package/dist/portable-files.js +0 -36
- package/dist/preserve.d.ts +0 -38
- package/dist/preserve.js +0 -1396
- package/dist/print.d.ts +0 -7
- package/dist/print.js +0 -406
- package/dist/reference-clipboard.d.ts +0 -8
- package/dist/reference-clipboard.js +0 -201
- package/dist/references.d.ts +0 -16
- package/dist/references.js +0 -418
- package/dist/scroll.d.ts +0 -15
- package/dist/scroll.js +0 -27
- package/dist/search.d.ts +0 -15
- package/dist/search.js +0 -202
- package/dist/selection.d.ts +0 -1
- package/dist/selection.js +0 -59
- package/dist/source.d.ts +0 -16
- package/dist/source.js +0 -57
- package/dist/spreadsheet.d.ts +0 -8
- package/dist/spreadsheet.js +0 -289
- package/dist/table-alignment.d.ts +0 -2
- package/dist/table-alignment.js +0 -46
- package/dist/tables.d.ts +0 -27
- package/dist/tables.js +0 -344
- package/dist/tasks.d.ts +0 -3
- package/dist/tasks.js +0 -51
- package/dist/text-ranges.d.ts +0 -29
- package/dist/text-ranges.js +0 -256
- package/dist/types.js +0 -8
- package/dist/wiki-view.d.ts +0 -21
- package/dist/wiki-view.js +0 -78
package/dist/linked-syntax.js
DELETED
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
import { $node, $remark } from '@milkdown/kit/utils';
|
|
2
|
-
import { defaultHandlers } from 'mdast-util-to-markdown';
|
|
3
|
-
const fromTable = (raw) => raw.replace(/(\\*)\|/g, (_match, escapes) => `${'\\'.repeat(Math.floor(escapes.length / 2))}|`);
|
|
4
|
-
const toTable = (raw) => raw.replace(/(\\*)\|/g, (_match, escapes) => `${'\\'.repeat(escapes.length * 2 + 1)}|`);
|
|
5
|
-
export function parseLinkedSyntax(raw, inTable = false) {
|
|
6
|
-
const source = inTable ? fromTable(raw) : raw;
|
|
7
|
-
const embed = source.startsWith('!');
|
|
8
|
-
const prefix = embed ? '![[' : '[[';
|
|
9
|
-
if (!source.startsWith(prefix) || !source.endsWith(']]'))
|
|
10
|
-
return undefined;
|
|
11
|
-
const content = source.slice(prefix.length, -2);
|
|
12
|
-
const parts = { target: '', fragment: '', alias: '' };
|
|
13
|
-
let section = 'target', hasFragment = false, hasAlias = false;
|
|
14
|
-
for (let index = 0; index < content.length; index++) {
|
|
15
|
-
const character = content[index];
|
|
16
|
-
if (character === '\\') {
|
|
17
|
-
const escaped = content[++index];
|
|
18
|
-
if (!escaped || !'[]|#\\'.includes(escaped))
|
|
19
|
-
return undefined;
|
|
20
|
-
parts[section] += escaped;
|
|
21
|
-
}
|
|
22
|
-
else if (character === '|') {
|
|
23
|
-
if (hasAlias)
|
|
24
|
-
return undefined;
|
|
25
|
-
hasAlias = true;
|
|
26
|
-
section = 'alias';
|
|
27
|
-
}
|
|
28
|
-
else if (character === '#' && section !== 'alias') {
|
|
29
|
-
if (hasFragment)
|
|
30
|
-
return undefined;
|
|
31
|
-
hasFragment = true;
|
|
32
|
-
section = 'fragment';
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
if ('[]'.includes(character) ||
|
|
36
|
-
(character.charCodeAt(0) < 32 && character !== '\t') ||
|
|
37
|
-
character === '\u007f')
|
|
38
|
-
return undefined;
|
|
39
|
-
parts[section] += character;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if ((!parts.target.trim() && !(hasFragment && parts.fragment.trim())) ||
|
|
43
|
-
(hasFragment && !parts.fragment.trim()) ||
|
|
44
|
-
(hasAlias && !parts.alias.trim()) ||
|
|
45
|
-
parts.target.trimStart().startsWith('^') ||
|
|
46
|
-
parts.fragment.trimStart().startsWith('^'))
|
|
47
|
-
return undefined;
|
|
48
|
-
const size = /^[ \t]*(\d{1,5})(?:x(\d{1,5}))?[ \t]*$/.exec(parts.alias);
|
|
49
|
-
if (embed &&
|
|
50
|
-
(!parts.target.trim() ||
|
|
51
|
-
(hasAlias &&
|
|
52
|
-
(!size ||
|
|
53
|
-
Number(size[1]) < 1 ||
|
|
54
|
-
(size[2] != null && Number(size[2]) < 1)))))
|
|
55
|
-
return undefined;
|
|
56
|
-
const target = embed ? parts.target.trim() : parts.target;
|
|
57
|
-
const fragment = hasFragment
|
|
58
|
-
? embed
|
|
59
|
-
? parts.fragment.trim()
|
|
60
|
-
: parts.fragment
|
|
61
|
-
: null;
|
|
62
|
-
return {
|
|
63
|
-
raw,
|
|
64
|
-
target,
|
|
65
|
-
fragment,
|
|
66
|
-
label: !embed && hasAlias
|
|
67
|
-
? parts.alias
|
|
68
|
-
: target + (fragment != null ? `#${fragment}` : ''),
|
|
69
|
-
width: embed && hasAlias ? Number(size[1]) : null,
|
|
70
|
-
embed,
|
|
71
|
-
inTable,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
function linkedTokenizer(embed) {
|
|
75
|
-
return function (effects, ok, nok) {
|
|
76
|
-
const prefix = embed ? '![[' : '[[';
|
|
77
|
-
let index = 0, raw = '';
|
|
78
|
-
return opening;
|
|
79
|
-
function consume(code) {
|
|
80
|
-
raw += code === -2 ? '\t' : code === -1 ? ' ' : String.fromCodePoint(code);
|
|
81
|
-
effects.consume(code);
|
|
82
|
-
}
|
|
83
|
-
function opening(code) {
|
|
84
|
-
if (code !== prefix.charCodeAt(index))
|
|
85
|
-
return nok(code);
|
|
86
|
-
if (!index)
|
|
87
|
-
effects.enter('inkkitLinkedSyntax');
|
|
88
|
-
consume(code);
|
|
89
|
-
index++;
|
|
90
|
-
return index === prefix.length ? body : opening;
|
|
91
|
-
}
|
|
92
|
-
function body(code) {
|
|
93
|
-
if (code === null ||
|
|
94
|
-
(code < 32 && code !== -2 && code !== -1 && code !== 9) ||
|
|
95
|
-
code === 91)
|
|
96
|
-
return nok(code);
|
|
97
|
-
consume(code);
|
|
98
|
-
if (code === 92)
|
|
99
|
-
return escaped;
|
|
100
|
-
return code === 93 ? closing : body;
|
|
101
|
-
}
|
|
102
|
-
function escaped(code) {
|
|
103
|
-
if (code === null || code < 32)
|
|
104
|
-
return nok(code);
|
|
105
|
-
consume(code);
|
|
106
|
-
return body;
|
|
107
|
-
}
|
|
108
|
-
function closing(code) {
|
|
109
|
-
if (code !== 93)
|
|
110
|
-
return nok(code);
|
|
111
|
-
consume(code);
|
|
112
|
-
if (!parseLinkedSyntax(raw) && !parseLinkedSyntax(raw, true))
|
|
113
|
-
return nok(code);
|
|
114
|
-
effects.exit('inkkitLinkedSyntax');
|
|
115
|
-
return ok;
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
function tableForm(raw, authoredInTable, outputInTable) {
|
|
120
|
-
if (authoredInTable === outputInTable)
|
|
121
|
-
return raw;
|
|
122
|
-
return outputInTable ? toTable(raw) : fromTable(raw);
|
|
123
|
-
}
|
|
124
|
-
export function wikiMarkdown(node, inTable = false) {
|
|
125
|
-
return tableForm(String(node.attrs.raw), Boolean(node.attrs.inTable), inTable);
|
|
126
|
-
}
|
|
127
|
-
export function wikiReference(node) {
|
|
128
|
-
return {
|
|
129
|
-
target: String(node.attrs.target),
|
|
130
|
-
...(node.attrs.fragment != null
|
|
131
|
-
? { fragment: String(node.attrs.fragment) }
|
|
132
|
-
: {}),
|
|
133
|
-
label: String(node.attrs.label),
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
export function fileReference(node) {
|
|
137
|
-
const reference = String(node.attrs.src ?? '');
|
|
138
|
-
const named = node.attrs.inkkitFileRaw != null;
|
|
139
|
-
const alt = String(node.attrs.alt ?? '');
|
|
140
|
-
const match = /\|(\d{1,5})$/.exec(alt);
|
|
141
|
-
const fragment = named
|
|
142
|
-
? node.attrs.inkkitFileFragment
|
|
143
|
-
: reference.includes('#')
|
|
144
|
-
? reference.slice(reference.indexOf('#') + 1)
|
|
145
|
-
: null;
|
|
146
|
-
const label = named
|
|
147
|
-
? String(node.attrs.inkkitFileTarget ?? '') +
|
|
148
|
-
(fragment != null ? `#${fragment}` : '')
|
|
149
|
-
: match
|
|
150
|
-
? alt.slice(0, match.index)
|
|
151
|
-
: alt;
|
|
152
|
-
const width = named && alt === label && node.attrs.inkkitFileWidth == null
|
|
153
|
-
? null
|
|
154
|
-
: match
|
|
155
|
-
? Number(match[1])
|
|
156
|
-
: null;
|
|
157
|
-
return {
|
|
158
|
-
reference,
|
|
159
|
-
kind: named ? 'wiki' : 'path',
|
|
160
|
-
...(fragment != null ? { fragment: String(fragment) } : {}),
|
|
161
|
-
...(label ? { label } : {}),
|
|
162
|
-
...(width != null ? { width } : {}),
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
export function namedFileMarkdown(node, inTable = false) {
|
|
166
|
-
if (node.attrs.inkkitFileRaw == null)
|
|
167
|
-
return undefined;
|
|
168
|
-
let raw = String(node.attrs.inkkitFileRaw);
|
|
169
|
-
const authoredInTable = Boolean(node.attrs.inkkitFileInTable);
|
|
170
|
-
const width = fileReference(node).width ?? null;
|
|
171
|
-
const original = node.attrs.inkkitFileWidth ?? null;
|
|
172
|
-
if (width !== original) {
|
|
173
|
-
if (authoredInTable)
|
|
174
|
-
raw = fromTable(raw);
|
|
175
|
-
if (original != null)
|
|
176
|
-
raw = raw.replace(/\|[ \t]*\d{1,5}(?:x\d{1,5})?[ \t]*\]\]$/, ']]');
|
|
177
|
-
if (width != null)
|
|
178
|
-
raw = `${raw.slice(0, -2)}|${width}]]`;
|
|
179
|
-
return inTable ? toTable(raw) : raw;
|
|
180
|
-
}
|
|
181
|
-
return tableForm(raw, authoredInTable, inTable);
|
|
182
|
-
}
|
|
183
|
-
export const wikiLinkSchema = $node('inkkit_wiki_link', () => ({
|
|
184
|
-
inline: true,
|
|
185
|
-
group: 'inline',
|
|
186
|
-
atom: true,
|
|
187
|
-
marks: '',
|
|
188
|
-
attrs: {
|
|
189
|
-
raw: { default: '' },
|
|
190
|
-
target: { default: '' },
|
|
191
|
-
fragment: { default: null },
|
|
192
|
-
label: { default: '' },
|
|
193
|
-
inTable: { default: false },
|
|
194
|
-
},
|
|
195
|
-
parseDOM: [
|
|
196
|
-
{
|
|
197
|
-
tag: 'span[data-inkkit-wiki]',
|
|
198
|
-
getAttrs(dom) {
|
|
199
|
-
const parsed = parseLinkedSyntax(dom.getAttribute('data-inkkit-wiki-raw') ?? '', dom.getAttribute('data-inkkit-wiki-table') === 'true');
|
|
200
|
-
return parsed && !parsed.embed
|
|
201
|
-
? {
|
|
202
|
-
raw: parsed.raw,
|
|
203
|
-
target: parsed.target,
|
|
204
|
-
fragment: parsed.fragment,
|
|
205
|
-
label: parsed.label,
|
|
206
|
-
inTable: parsed.inTable,
|
|
207
|
-
}
|
|
208
|
-
: false;
|
|
209
|
-
},
|
|
210
|
-
},
|
|
211
|
-
],
|
|
212
|
-
toDOM: (node) => [
|
|
213
|
-
'span',
|
|
214
|
-
{
|
|
215
|
-
'data-inkkit-wiki': node.attrs.target,
|
|
216
|
-
'data-inkkit-fragment': node.attrs.fragment ?? '',
|
|
217
|
-
'data-inkkit-wiki-raw': node.attrs.raw,
|
|
218
|
-
'data-inkkit-wiki-table': String(node.attrs.inTable),
|
|
219
|
-
role: 'link',
|
|
220
|
-
tabindex: '0',
|
|
221
|
-
},
|
|
222
|
-
node.attrs.label,
|
|
223
|
-
],
|
|
224
|
-
parseMarkdown: {
|
|
225
|
-
match: (node) => node.type === 'inkkitWikiLink',
|
|
226
|
-
runner(state, node, type) {
|
|
227
|
-
state.addNode(type, {
|
|
228
|
-
raw: node.raw,
|
|
229
|
-
target: node.target,
|
|
230
|
-
fragment: node.fragment,
|
|
231
|
-
label: node.label,
|
|
232
|
-
inTable: node.inTable,
|
|
233
|
-
});
|
|
234
|
-
},
|
|
235
|
-
},
|
|
236
|
-
toMarkdown: {
|
|
237
|
-
match: (node) => node.type.name === 'inkkit_wiki_link',
|
|
238
|
-
runner(state, node) {
|
|
239
|
-
state.addNode('inkkitWikiLink', undefined, node.attrs.label, {
|
|
240
|
-
raw: node.attrs.raw,
|
|
241
|
-
target: node.attrs.target,
|
|
242
|
-
fragment: node.attrs.fragment,
|
|
243
|
-
label: node.attrs.label,
|
|
244
|
-
inTable: node.attrs.inTable,
|
|
245
|
-
});
|
|
246
|
-
},
|
|
247
|
-
},
|
|
248
|
-
}));
|
|
249
|
-
export function linkedSyntax(wikiLinks, files) {
|
|
250
|
-
const syntax = { text: {} };
|
|
251
|
-
if (wikiLinks)
|
|
252
|
-
syntax.text[91] = {
|
|
253
|
-
name: 'inkkitWikiLink',
|
|
254
|
-
tokenize: linkedTokenizer(false),
|
|
255
|
-
previous: (code) => code !== 33 && code !== 91,
|
|
256
|
-
};
|
|
257
|
-
if (files)
|
|
258
|
-
syntax.text[33] = {
|
|
259
|
-
name: 'inkkitNamedFile',
|
|
260
|
-
tokenize: linkedTokenizer(true),
|
|
261
|
-
};
|
|
262
|
-
const from = {
|
|
263
|
-
enter: {
|
|
264
|
-
inkkitLinkedSyntax(token) {
|
|
265
|
-
const inTable = this.stack.some((node) => node.type === 'tableCell');
|
|
266
|
-
const parsed = parseLinkedSyntax(this.sliceSerialize(token), inTable);
|
|
267
|
-
if (!parsed) {
|
|
268
|
-
this.enter({ type: 'text', value: this.sliceSerialize(token) }, token);
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
if (parsed.embed)
|
|
272
|
-
this.enter({
|
|
273
|
-
type: 'image',
|
|
274
|
-
url: parsed.target +
|
|
275
|
-
(parsed.fragment != null ? `#${parsed.fragment}` : ''),
|
|
276
|
-
alt: parsed.label + (parsed.width != null ? `|${parsed.width}` : ''),
|
|
277
|
-
title: null,
|
|
278
|
-
inkkitFileRaw: parsed.raw,
|
|
279
|
-
inkkitFileTarget: parsed.target,
|
|
280
|
-
inkkitFileFragment: parsed.fragment,
|
|
281
|
-
inkkitFileWidth: parsed.width,
|
|
282
|
-
inkkitFileInTable: inTable,
|
|
283
|
-
}, token);
|
|
284
|
-
else
|
|
285
|
-
this.enter({
|
|
286
|
-
type: 'inkkitWikiLink',
|
|
287
|
-
value: parsed.label,
|
|
288
|
-
raw: parsed.raw,
|
|
289
|
-
target: parsed.target,
|
|
290
|
-
fragment: parsed.fragment,
|
|
291
|
-
label: parsed.label,
|
|
292
|
-
inTable,
|
|
293
|
-
}, token);
|
|
294
|
-
},
|
|
295
|
-
},
|
|
296
|
-
exit: {
|
|
297
|
-
inkkitLinkedSyntax(token) {
|
|
298
|
-
this.exit(token);
|
|
299
|
-
},
|
|
300
|
-
},
|
|
301
|
-
};
|
|
302
|
-
const wiki = (node, _parent, state) => tableForm(String(node.raw), Boolean(node.inTable), state.stack.includes('tableCell'));
|
|
303
|
-
const named = (node, parent, state, info) => {
|
|
304
|
-
if (node.inkkitFileRaw != null)
|
|
305
|
-
return tableForm(String(node.inkkitFileRaw), Boolean(node.inkkitFileInTable), state.stack.includes('tableCell'));
|
|
306
|
-
return defaultHandlers.image(node, parent, state, info);
|
|
307
|
-
};
|
|
308
|
-
// Standard image handling is installed by CommonMark; wrap it only for authored named tokens.
|
|
309
|
-
return $remark('inkkitLinkedSyntax', () => function () {
|
|
310
|
-
const data = this.data();
|
|
311
|
-
(data.micromarkExtensions ??= []).push(syntax);
|
|
312
|
-
(data.fromMarkdownExtensions ??= []).push(from);
|
|
313
|
-
(data.toMarkdownExtensions ??= []).push({
|
|
314
|
-
handlers: {
|
|
315
|
-
inkkitWikiLink: wiki,
|
|
316
|
-
...(files ? { image: named } : {}),
|
|
317
|
-
},
|
|
318
|
-
});
|
|
319
|
-
});
|
|
320
|
-
}
|
package/dist/literals.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { Literal } from 'mdast';
|
|
2
|
-
import { type CommentSpan } from './comments.js';
|
|
3
|
-
interface InkKitLiteral extends Literal {
|
|
4
|
-
type: 'inkkitLiteral';
|
|
5
|
-
comments?: CommentSpan[];
|
|
6
|
-
}
|
|
7
|
-
declare module 'mdast' {
|
|
8
|
-
interface BlockContentMap {
|
|
9
|
-
inkkitLiteral: InkKitLiteral;
|
|
10
|
-
}
|
|
11
|
-
interface RootContentMap {
|
|
12
|
-
inkkitLiteral: InkKitLiteral;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export declare function sourceFrontmatter(source: string): string | undefined;
|
|
16
|
-
export declare function lineBreakHTML(value: string): boolean;
|
|
17
|
-
export declare function createLiteralPreservation(images: boolean): import("@milkdown/kit/utils").$Remark<"preserveLiterals", unknown>;
|
|
18
|
-
export declare const preserveLiterals: import("@milkdown/kit/utils").$Remark<"preserveLiterals", unknown>;
|
|
19
|
-
export declare const literalBlock: import("@milkdown/kit/utils").$Node;
|
|
20
|
-
export {};
|
package/dist/literals.js
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import { $node, $remark } from '@milkdown/kit/utils';
|
|
2
|
-
import { commentSource, literalCommentSpans, } from './comments.js';
|
|
3
|
-
const unsupported = new Set(['html', 'image', 'imageReference']);
|
|
4
|
-
export function sourceFrontmatter(source) {
|
|
5
|
-
return /^(---|\+\+\+)\r?\n[\s\S]*?\r?\n\1(?:\r?\n|$)/.exec(source)?.[0];
|
|
6
|
-
}
|
|
7
|
-
export function lineBreakHTML(value) {
|
|
8
|
-
return ['<br />', '<br>', '<br >', '<br/>'].includes(value.trim());
|
|
9
|
-
}
|
|
10
|
-
function restoreInlineBreaks(node) {
|
|
11
|
-
// A cell cannot hold a line ending, so even a lone break there is content.
|
|
12
|
-
if (((node.type === 'paragraph' || node.type === 'heading') &&
|
|
13
|
-
node.children.length > 1) ||
|
|
14
|
-
node.type === 'tableCell') {
|
|
15
|
-
node.children = node.children.map((child) => child.type === 'html' && lineBreakHTML(child.value)
|
|
16
|
-
? {
|
|
17
|
-
type: 'break',
|
|
18
|
-
data: { inkkitHTMLBreak: true },
|
|
19
|
-
position: child.position,
|
|
20
|
-
}
|
|
21
|
-
: child);
|
|
22
|
-
}
|
|
23
|
-
if ('children' in node)
|
|
24
|
-
node.children.forEach(restoreInlineBreaks);
|
|
25
|
-
}
|
|
26
|
-
function containsUnsupported(node, images, inline = false) {
|
|
27
|
-
// Only a standalone break represents a spacer; inline HTML must remain literal.
|
|
28
|
-
if (!inline && node.type === 'html' && lineBreakHTML(node.value))
|
|
29
|
-
return false;
|
|
30
|
-
if (node.type === 'paragraph' && node.children.length === 1) {
|
|
31
|
-
const child = node.children[0];
|
|
32
|
-
if (child?.type === 'html' && lineBreakHTML(child.value))
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
// GFM ignores cells past the header's count, so a grid cannot show them.
|
|
36
|
-
if (node.type === 'table' &&
|
|
37
|
-
node.children.some((row) => row.children.length > (node.children[0]?.children.length ?? 0)))
|
|
38
|
-
return true;
|
|
39
|
-
return ((unsupported.has(node.type) && !(images && node.type === 'image')) ||
|
|
40
|
-
('children' in node &&
|
|
41
|
-
node.children.some((child) => containsUnsupported(child, images, inline || node.type === 'paragraph' || node.type === 'heading'))));
|
|
42
|
-
}
|
|
43
|
-
function containsUnresolved(node, source) {
|
|
44
|
-
if (node.type === 'text') {
|
|
45
|
-
const start = node.position?.start.offset;
|
|
46
|
-
const end = node.position?.end.offset;
|
|
47
|
-
if (start == null || end == null)
|
|
48
|
-
return false;
|
|
49
|
-
const raw = source.slice(start, end);
|
|
50
|
-
return /(?<!\\)\[\^[^\]\n]+\]|(?<!\\)\[[^\]\n]+\](?:\[[^\]\n]*\])?/.test(raw);
|
|
51
|
-
}
|
|
52
|
-
return ('children' in node &&
|
|
53
|
-
node.children.some((child) => containsUnresolved(child, source)));
|
|
54
|
-
}
|
|
55
|
-
function containsUnsupportedLinked(node, source) {
|
|
56
|
-
const start = node.position?.start.offset, end = node.position?.end.offset;
|
|
57
|
-
if (start == null || end == null || node.type === 'definition')
|
|
58
|
-
return false;
|
|
59
|
-
const supported = [];
|
|
60
|
-
const visit = (child) => {
|
|
61
|
-
if ([
|
|
62
|
-
'inkkitWikiLink',
|
|
63
|
-
'image',
|
|
64
|
-
'code',
|
|
65
|
-
'inlineCode',
|
|
66
|
-
'link',
|
|
67
|
-
'inkkitCommentInline',
|
|
68
|
-
'inkkitCommentBlock',
|
|
69
|
-
].includes(child.type)) {
|
|
70
|
-
const from = child.position?.start.offset, to = child.position?.end.offset;
|
|
71
|
-
if (from != null && to != null)
|
|
72
|
-
supported.push({ from, to });
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
if ('children' in child)
|
|
76
|
-
child.children.forEach(visit);
|
|
77
|
-
};
|
|
78
|
-
visit(node);
|
|
79
|
-
for (const match of source
|
|
80
|
-
.slice(start, end)
|
|
81
|
-
.matchAll(/!?\[\[[^\r\n]*?\]\]/g)) {
|
|
82
|
-
const from = start + match.index, to = from + match[0].length;
|
|
83
|
-
let escapes = 0;
|
|
84
|
-
while (from - escapes > 0 && source[from - escapes - 1] === '\\')
|
|
85
|
-
escapes++;
|
|
86
|
-
if (escapes % 2)
|
|
87
|
-
continue;
|
|
88
|
-
if (!supported.some((span) => span.from <= from && span.to >= to))
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
// Keep syntax we cannot faithfully edit as literal text, without making the rest
|
|
94
|
-
// of the document a source editor or allowing HTML and image network requests.
|
|
95
|
-
export function createLiteralPreservation(images) {
|
|
96
|
-
return $remark('preserveLiterals', () => () => (tree, file) => {
|
|
97
|
-
restoreInlineBreaks(tree);
|
|
98
|
-
// Micromark's positions exclude an initial byte-order mark.
|
|
99
|
-
const source = String(file.value).replace(/^\uFEFF/, '');
|
|
100
|
-
const frontmatter = sourceFrontmatter(source);
|
|
101
|
-
const frontmatterEnd = frontmatter?.length ?? 0;
|
|
102
|
-
const preserveBlock = (node, depth = 0) => {
|
|
103
|
-
if (node.type === 'footnoteDefinition') {
|
|
104
|
-
node.children = node.children.map((child) => preserveBlock(child, depth + 1));
|
|
105
|
-
return node;
|
|
106
|
-
}
|
|
107
|
-
const start = node.position?.start.offset;
|
|
108
|
-
const end = node.position?.end.offset;
|
|
109
|
-
if (start == null ||
|
|
110
|
-
end == null ||
|
|
111
|
-
(!containsUnsupported(node, images) &&
|
|
112
|
-
!containsUnresolved(node, source) &&
|
|
113
|
-
!containsUnsupportedLinked(node, source)))
|
|
114
|
-
return node;
|
|
115
|
-
let raw = source.slice(start, end);
|
|
116
|
-
// Definition indentation is restored by the footnote serializer.
|
|
117
|
-
for (let index = 0; index < depth; index++)
|
|
118
|
-
raw = raw.replace(/\r?\n(?: {4}|\t)/g, '\n');
|
|
119
|
-
return {
|
|
120
|
-
type: 'inkkitLiteral',
|
|
121
|
-
value: raw,
|
|
122
|
-
comments: literalCommentSpans(raw),
|
|
123
|
-
position: node.position,
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
const blocks = [];
|
|
127
|
-
if (frontmatter)
|
|
128
|
-
blocks.push({
|
|
129
|
-
type: 'inkkitLiteral',
|
|
130
|
-
value: frontmatter.trimEnd(),
|
|
131
|
-
position: {
|
|
132
|
-
start: { line: 1, column: 1, offset: 0 },
|
|
133
|
-
end: {
|
|
134
|
-
line: 1,
|
|
135
|
-
column: 1,
|
|
136
|
-
offset: frontmatter.trimEnd().length,
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
});
|
|
140
|
-
for (const node of tree.children) {
|
|
141
|
-
const start = node.position?.start.offset;
|
|
142
|
-
const end = node.position?.end.offset;
|
|
143
|
-
if (start == null || end == null) {
|
|
144
|
-
blocks.push(node);
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
|
-
if (start < frontmatterEnd) {
|
|
148
|
-
// TOML delimiters are ordinary paragraph text to CommonMark, so a
|
|
149
|
-
// paragraph may also contain body text immediately after the header.
|
|
150
|
-
if (end > frontmatterEnd)
|
|
151
|
-
blocks.push({
|
|
152
|
-
type: 'inkkitLiteral',
|
|
153
|
-
value: source.slice(frontmatterEnd, end),
|
|
154
|
-
position: {
|
|
155
|
-
start: { line: 1, column: 1, offset: frontmatterEnd },
|
|
156
|
-
end: node.position.end,
|
|
157
|
-
},
|
|
158
|
-
});
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
if (node.type === 'inkkitLiteral')
|
|
162
|
-
node.comments = literalCommentSpans(node.value);
|
|
163
|
-
blocks.push(preserveBlock(node));
|
|
164
|
-
}
|
|
165
|
-
tree.children = blocks;
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
export const preserveLiterals = createLiteralPreservation(false);
|
|
169
|
-
export const literalBlock = $node('literal_markdown', () => ({
|
|
170
|
-
group: 'block',
|
|
171
|
-
content: '(text | comment_inline)*',
|
|
172
|
-
marks: '',
|
|
173
|
-
code: true,
|
|
174
|
-
defining: true,
|
|
175
|
-
parseDOM: [
|
|
176
|
-
{ tag: 'pre.literal-markdown', preserveWhitespace: 'full', priority: 100 },
|
|
177
|
-
],
|
|
178
|
-
toDOM: () => [
|
|
179
|
-
'pre',
|
|
180
|
-
{ class: 'literal-markdown', 'aria-label': 'Preserved Markdown' },
|
|
181
|
-
0,
|
|
182
|
-
],
|
|
183
|
-
parseMarkdown: {
|
|
184
|
-
match: (node) => node.type === 'inkkitLiteral',
|
|
185
|
-
runner: (state, node, type) => {
|
|
186
|
-
state.openNode(type);
|
|
187
|
-
const value = String(node.value ?? '');
|
|
188
|
-
let cursor = 0;
|
|
189
|
-
for (const span of node.comments ?? []) {
|
|
190
|
-
if (span.start > cursor)
|
|
191
|
-
state.addText(value.slice(cursor, span.start));
|
|
192
|
-
state.openNode(state.schema.nodes.comment_inline, {
|
|
193
|
-
syntax: span.syntax,
|
|
194
|
-
block: Boolean(span.block),
|
|
195
|
-
});
|
|
196
|
-
if (span.value)
|
|
197
|
-
state.addText(span.value);
|
|
198
|
-
state.closeNode();
|
|
199
|
-
cursor = span.end;
|
|
200
|
-
}
|
|
201
|
-
if (cursor < value.length)
|
|
202
|
-
state.addText(value.slice(cursor));
|
|
203
|
-
state.closeNode();
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
toMarkdown: {
|
|
207
|
-
match: (node) => node.type.name === 'literal_markdown',
|
|
208
|
-
runner: (state, node) => {
|
|
209
|
-
let source = '';
|
|
210
|
-
node.forEach((child) => {
|
|
211
|
-
source += child.isText ? child.text : commentSource(child);
|
|
212
|
-
});
|
|
213
|
-
state.addNode('html', undefined, source);
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
}));
|
package/dist/mermaid.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { Node as ProseNode } from '@milkdown/kit/prose/model';
|
|
2
|
-
import { type PortableImage } from './types.js';
|
|
3
|
-
export declare function isMermaid(node: ProseNode): boolean;
|
|
4
|
-
interface Annotations {
|
|
5
|
-
names: string[];
|
|
6
|
-
rest: string;
|
|
7
|
-
}
|
|
8
|
-
export declare function validateDiagram(source: string): Annotations;
|
|
9
|
-
interface ParsedDiagram {
|
|
10
|
-
type: string;
|
|
11
|
-
db: unknown;
|
|
12
|
-
}
|
|
13
|
-
interface Mermaid {
|
|
14
|
-
initialize(config: object): void;
|
|
15
|
-
render(id: string, text: string, container?: Element): Promise<{
|
|
16
|
-
svg: string;
|
|
17
|
-
}>;
|
|
18
|
-
mermaidAPI: {
|
|
19
|
-
getDiagramFromText(text: string): Promise<ParsedDiagram>;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
export declare function registerMermaid(load: () => Promise<Mermaid>): void;
|
|
23
|
-
export declare const diagramsAvailable: () => boolean;
|
|
24
|
-
export declare function safeDiagramSVG(svg: string): string;
|
|
25
|
-
export declare function renderDiagram(source: string): Promise<string>;
|
|
26
|
-
export declare function diagramImage(source: string): Promise<PortableImage>;
|
|
27
|
-
export declare function mermaidPreview(onError: (error: Error) => void): import("@milkdown/kit/utils").$Prose;
|
|
28
|
-
export {};
|