@airalogy/aimd-editor 1.10.0 → 1.12.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/README.md +14 -1
- package/README.zh-CN.md +14 -1
- package/dist/{AimdEditorTopBar.vue_vue_type_script_setup_true_lang-CODh6fyp.js → AimdEditorTopBar.vue_vue_type_script_setup_true_lang-BXsn4cFX.js} +3 -3
- package/dist/AimdSourceEditor.vue_vue_type_script_setup_true_lang-CJJTlVZ7.js +422 -0
- package/dist/{AimdWysiwygEditor.vue_vue_type_script_setup_true_lang-DPs--N5C.js → AimdWysiwygEditor.vue_vue_type_script_setup_true_lang-Dme3UQEf.js} +487 -475
- package/dist/aimd-editor.css +1 -1
- package/dist/authoring.js +10 -0
- package/dist/embedded.js +2 -2
- package/dist/{AimdSourceEditor.vue_vue_type_script_setup_true_lang-DCbNbka1.js → index-BqB8Xukp.js} +1505 -1542
- package/dist/index.js +44 -36
- package/dist/monaco.js +1 -1
- package/dist/{theme-Cu18_uZ_.js → theme-CB0dPzmd.js} +31 -16
- package/dist/vue.js +3 -3
- package/dist/wysiwyg.js +1 -1
- package/package.json +7 -3
- package/src/authoring/fig.ts +368 -0
- package/src/authoring/index.ts +15 -0
- package/src/index.ts +1 -0
- package/src/language-config.ts +16 -1
- package/src/vue/AimdEditor.vue +3 -1
- package/src/vue/AimdSourceEditor.vue +66 -1
- package/src/vue/aimdDiagnostics.ts +81 -1
- package/src/vue/locales.ts +18 -0
- package/src/vue/useEditorContent.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -1,44 +1,52 @@
|
|
|
1
|
-
import { A as i, a as s, b as d, D as o, K as
|
|
2
|
-
import {
|
|
3
|
-
import { _ as
|
|
4
|
-
import {
|
|
1
|
+
import { A as i, a as s, b as d, D as o, K as r, M as m, c as t, d as A, e as l, f as n, g as I, l as D, s as E } from "./theme-CB0dPzmd.js";
|
|
2
|
+
import { A as u, a as c, c as F, b as _, n as p, p as f, s as g } from "./index-BqB8Xukp.js";
|
|
3
|
+
import { _ as O, a as k, b as x, c as L, u as S } from "./AimdEditorTopBar.vue_vue_type_script_setup_true_lang-BXsn4cFX.js";
|
|
4
|
+
import { _ as y } from "./AimdSourceEditor.vue_vue_type_script_setup_true_lang-CJJTlVZ7.js";
|
|
5
|
+
import { A as P, a as R, _ as w, D as B, M as h, b as C, c as v, d as K, e as V, f as Y, g as j, h as z, i as G, j as Q, k as U, l as W, m as q, n as H, r as J } from "./AimdWysiwygEditor.vue_vue_type_script_setup_true_lang-Dme3UQEf.js";
|
|
5
6
|
export {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
P as AIMD_FIELD_TYPES,
|
|
8
|
+
R as AIMD_FIELD_TYPE_DEFINITIONS,
|
|
9
|
+
u as AIMD_FIG_ID_PATTERN,
|
|
10
|
+
O as AimdEditor,
|
|
11
|
+
k as AimdEditorToolbar,
|
|
12
|
+
x as AimdEditorTopBar,
|
|
13
|
+
L as AimdFieldDialog,
|
|
14
|
+
c as AimdFormalOutputError,
|
|
15
|
+
y as AimdSourceEditor,
|
|
13
16
|
i as AimdSuffix,
|
|
14
17
|
s as AimdToken,
|
|
15
18
|
d as AimdTokenDefinition,
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
w as AimdWysiwygEditor,
|
|
20
|
+
B as DEFAULT_AIMD_EDITOR_LOCALE,
|
|
18
21
|
o as DelimiterDefinition,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
r as KeywordDefinition,
|
|
23
|
+
h as MD_TOOLBAR_ITEMS,
|
|
24
|
+
C as MD_TOOLBAR_ITEM_DEFINITIONS,
|
|
25
|
+
m as MarkupDefinition,
|
|
26
|
+
v as aimdFieldInputRule,
|
|
27
|
+
K as aimdFieldNode,
|
|
28
|
+
V as aimdFieldView,
|
|
29
|
+
Y as aimdMilkdownPlugins,
|
|
30
|
+
j as aimdRemarkPlugin,
|
|
28
31
|
t as aimdTheme,
|
|
29
32
|
A as aimdTokenColors,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
l as
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
33
|
+
z as buildAimdSyntax,
|
|
34
|
+
F as collectAimdFigureIds,
|
|
35
|
+
l as completionItemProvider,
|
|
36
|
+
n as conf,
|
|
37
|
+
G as createAimdEditorMessages,
|
|
38
|
+
I as createAimdExtendedTheme,
|
|
39
|
+
Q as createAimdFieldTypes,
|
|
40
|
+
_ as createAimdFigureId,
|
|
41
|
+
U as createAimdVarTypePresets,
|
|
42
|
+
W as createMdToolbarItems,
|
|
43
|
+
q as getDefaultAimdFields,
|
|
44
|
+
H as getQuickAimdSyntax,
|
|
45
|
+
D as language,
|
|
46
|
+
p as normalizeAimdFigureIds,
|
|
47
|
+
f as prepareAimdForFormalOutput,
|
|
48
|
+
J as resolveAimdEditorLocale,
|
|
49
|
+
g as scanAimdFigureBlocks,
|
|
50
|
+
E as scopeName,
|
|
51
|
+
S as useEditorContent
|
|
44
52
|
};
|
package/dist/monaco.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as a, a as o, b as s, D as n, K as m, M as d, c as t, d as f, e as r, f as D, g as c, l, s as A } from "./theme-
|
|
1
|
+
import { A as a, a as o, b as s, D as n, K as m, M as d, c as t, d as f, e as r, f as D, g as c, l, s as A } from "./theme-CB0dPzmd.js";
|
|
2
2
|
export {
|
|
3
3
|
a as AimdSuffix,
|
|
4
4
|
o as AimdToken,
|
|
@@ -235,7 +235,7 @@ function r(o) {
|
|
|
235
235
|
function i(o) {
|
|
236
236
|
return n("keyword", o, t);
|
|
237
237
|
}
|
|
238
|
-
const
|
|
238
|
+
const I = {
|
|
239
239
|
...r("variable"),
|
|
240
240
|
...r("variable-table"),
|
|
241
241
|
...r("checkpoint"),
|
|
@@ -254,7 +254,7 @@ const m = {
|
|
|
254
254
|
...n("delimiter", "parameter", t),
|
|
255
255
|
...n("delimiter", "colon", t),
|
|
256
256
|
...n("delimiter", "bracket", t)
|
|
257
|
-
},
|
|
257
|
+
}, k = {
|
|
258
258
|
...n("keyword", "control", t),
|
|
259
259
|
...n("variable", "parameter", t),
|
|
260
260
|
...n("metatag", "link", t),
|
|
@@ -277,17 +277,17 @@ const m = {
|
|
|
277
277
|
}, e = {
|
|
278
278
|
...n("punctuation", "definition", "begin", t),
|
|
279
279
|
...n("punctuation", "definition", "end", t),
|
|
280
|
-
...
|
|
280
|
+
...I,
|
|
281
281
|
...A,
|
|
282
282
|
...g,
|
|
283
|
-
...
|
|
284
|
-
},
|
|
283
|
+
...k
|
|
284
|
+
}, u = "text.html.markdown.aimd", E = [
|
|
285
285
|
..._.autoClosingPairs || []
|
|
286
|
-
],
|
|
286
|
+
], D = E;
|
|
287
287
|
function b(o, s = "|") {
|
|
288
288
|
return o.split(s);
|
|
289
289
|
}
|
|
290
|
-
const p = b("var|var_table|check|step|ref_step|ref_var|ref_fig|ref_media|ref_table|table_link"),
|
|
290
|
+
const p = b("var|var_table|check|step|ref_step|ref_var|ref_fig|ref_media|ref_table|table_link|workflow|connectors|collectors"), R = {
|
|
291
291
|
...d,
|
|
292
292
|
tokenPostfix: ".aimd",
|
|
293
293
|
keywords: p,
|
|
@@ -299,6 +299,21 @@ const p = b("var|var_table|check|step|ref_step|ref_var|ref_fig|ref_media|ref_tab
|
|
|
299
299
|
next: "@quizCodeblock",
|
|
300
300
|
nextEmbedded: "yaml"
|
|
301
301
|
}],
|
|
302
|
+
[/^\s*(```|~~~)\s*workflow(?:\s+.*)?\s*$/, {
|
|
303
|
+
token: "string",
|
|
304
|
+
next: "@quizCodeblock",
|
|
305
|
+
nextEmbedded: "yaml"
|
|
306
|
+
}],
|
|
307
|
+
[/^\s*(```|~~~)\s*connectors(?:\s+.*)?\s*$/, {
|
|
308
|
+
token: "string",
|
|
309
|
+
next: "@quizCodeblock",
|
|
310
|
+
nextEmbedded: "yaml"
|
|
311
|
+
}],
|
|
312
|
+
[/^\s*(```|~~~)\s*collectors(?:\s+.*)?\s*$/, {
|
|
313
|
+
token: "string",
|
|
314
|
+
next: "@quizCodeblock",
|
|
315
|
+
nextEmbedded: "yaml"
|
|
316
|
+
}],
|
|
302
317
|
[/^\s*(```|~~~)\s*(fig|media)(?:\s+.*)?\s*$/, {
|
|
303
318
|
token: "string",
|
|
304
319
|
next: "@quizCodeblock",
|
|
@@ -419,7 +434,7 @@ const p = b("var|var_table|check|step|ref_step|ref_var|ref_fig|ref_media|ref_tab
|
|
|
419
434
|
}, M = {
|
|
420
435
|
..._,
|
|
421
436
|
autoClosingPairs: E,
|
|
422
|
-
surroundingPairs:
|
|
437
|
+
surroundingPairs: D
|
|
423
438
|
}, f = {
|
|
424
439
|
provideCompletionItems: (o, s) => ({ suggestions: p.map((c) => ({
|
|
425
440
|
label: c,
|
|
@@ -427,7 +442,7 @@ const p = b("var|var_table|check|step|ref_step|ref_var|ref_fig|ref_media|ref_tab
|
|
|
427
442
|
insertText: c,
|
|
428
443
|
insertTextRules: l.CompletionItemInsertTextRule.InsertAsSnippet
|
|
429
444
|
})) })
|
|
430
|
-
},
|
|
445
|
+
}, m = [
|
|
431
446
|
// {{ and }} brackets - green
|
|
432
447
|
{
|
|
433
448
|
scope: [
|
|
@@ -562,7 +577,7 @@ const p = b("var|var_table|check|step|ref_step|ref_var|ref_fig|ref_media|ref_tab
|
|
|
562
577
|
], N = {
|
|
563
578
|
name: "aimd-theme",
|
|
564
579
|
type: "light",
|
|
565
|
-
settings:
|
|
580
|
+
settings: m,
|
|
566
581
|
colors: {}
|
|
567
582
|
};
|
|
568
583
|
function x(o, s = "aimd-extended") {
|
|
@@ -570,21 +585,21 @@ function x(o, s = "aimd-extended") {
|
|
|
570
585
|
return {
|
|
571
586
|
...o,
|
|
572
587
|
name: s,
|
|
573
|
-
settings: [...a, ...
|
|
588
|
+
settings: [...a, ...m]
|
|
574
589
|
};
|
|
575
590
|
}
|
|
576
591
|
export {
|
|
577
592
|
t as A,
|
|
578
593
|
g as D,
|
|
579
594
|
A as K,
|
|
580
|
-
|
|
595
|
+
I as M,
|
|
581
596
|
e as a,
|
|
582
|
-
|
|
597
|
+
k as b,
|
|
583
598
|
N as c,
|
|
584
|
-
|
|
599
|
+
m as d,
|
|
585
600
|
f as e,
|
|
586
601
|
M as f,
|
|
587
602
|
x as g,
|
|
588
|
-
|
|
589
|
-
|
|
603
|
+
R as l,
|
|
604
|
+
u as s
|
|
590
605
|
};
|
package/dist/vue.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _ as e, a as d, b as s, c as r, u as o } from "./AimdEditorTopBar.vue_vue_type_script_setup_true_lang-
|
|
2
|
-
import { _ as m } from "./AimdSourceEditor.vue_vue_type_script_setup_true_lang-
|
|
3
|
-
import { A as E, a as l, _ as I, D as _, M as T, b as D, c as F, d as M, e as u, f as c, g as n, h as g, i as L, j as O, k as p, l as S, m as y, n as b, r as f } from "./AimdWysiwygEditor.vue_vue_type_script_setup_true_lang-
|
|
1
|
+
import { _ as e, a as d, b as s, c as r, u as o } from "./AimdEditorTopBar.vue_vue_type_script_setup_true_lang-BXsn4cFX.js";
|
|
2
|
+
import { _ as m } from "./AimdSourceEditor.vue_vue_type_script_setup_true_lang-CJJTlVZ7.js";
|
|
3
|
+
import { A as E, a as l, _ as I, D as _, M as T, b as D, c as F, d as M, e as u, f as c, g as n, h as g, i as L, j as O, k as p, l as S, m as y, n as b, r as f } from "./AimdWysiwygEditor.vue_vue_type_script_setup_true_lang-Dme3UQEf.js";
|
|
4
4
|
export {
|
|
5
5
|
E as AIMD_FIELD_TYPES,
|
|
6
6
|
l as AIMD_FIELD_TYPE_DEFINITIONS,
|
package/dist/wysiwyg.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as a, D as r, i, j as d, k as t, r as A } from "./AimdWysiwygEditor.vue_vue_type_script_setup_true_lang-
|
|
1
|
+
import { _ as a, D as r, i, j as d, k as t, r as A } from "./AimdWysiwygEditor.vue_vue_type_script_setup_true_lang-Dme3UQEf.js";
|
|
2
2
|
export {
|
|
3
3
|
a as AimdWysiwygEditor,
|
|
4
4
|
r as DEFAULT_AIMD_EDITOR_LOCALE,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@airalogy/aimd-editor",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.12.0",
|
|
5
5
|
"description": "AIMD (Airalogy Markdown) editor with Monaco source mode and Milkdown WYSIWYG mode",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -31,6 +31,10 @@
|
|
|
31
31
|
"types": "./src/monaco.ts",
|
|
32
32
|
"import": "./src/monaco.ts"
|
|
33
33
|
},
|
|
34
|
+
"./authoring": {
|
|
35
|
+
"types": "./src/authoring/index.ts",
|
|
36
|
+
"import": "./src/authoring/index.ts"
|
|
37
|
+
},
|
|
34
38
|
"./vue": {
|
|
35
39
|
"types": "./src/vue/index.ts",
|
|
36
40
|
"import": "./src/vue/index.ts"
|
|
@@ -59,8 +63,8 @@
|
|
|
59
63
|
"@milkdown/kit": "^7.18.0",
|
|
60
64
|
"@milkdown/theme-nord": "^7.18.0",
|
|
61
65
|
"@milkdown/vue": "^7.18.0",
|
|
62
|
-
"@airalogy/aimd-
|
|
63
|
-
"@airalogy/aimd-
|
|
66
|
+
"@airalogy/aimd-core": "^2.16.0",
|
|
67
|
+
"@airalogy/aimd-renderer": "^2.13.0"
|
|
64
68
|
},
|
|
65
69
|
"peerDependencies": {
|
|
66
70
|
"monaco-editor": ">=0.50.0",
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import { validateFigDefinitions } from '@airalogy/aimd-core/parser'
|
|
2
|
+
|
|
3
|
+
export const AIMD_FIG_ID_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/
|
|
4
|
+
|
|
5
|
+
export interface AimdTextEdit {
|
|
6
|
+
startOffset: number
|
|
7
|
+
endOffset: number
|
|
8
|
+
text: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface AimdFigureSourceField {
|
|
12
|
+
value: string
|
|
13
|
+
lineStartOffset: number
|
|
14
|
+
lineEndOffset: number
|
|
15
|
+
indentation: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface AimdFigureBlockInfo {
|
|
19
|
+
startOffset: number
|
|
20
|
+
endOffset: number
|
|
21
|
+
bodyStartOffset: number
|
|
22
|
+
bodyEndOffset: number
|
|
23
|
+
indentation: string
|
|
24
|
+
lineEnding: string
|
|
25
|
+
id?: AimdFigureSourceField
|
|
26
|
+
src?: AimdFigureSourceField
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface GeneratedAimdFigureId {
|
|
30
|
+
id: string
|
|
31
|
+
src: string
|
|
32
|
+
blockStartOffset: number
|
|
33
|
+
edit: AimdTextEdit
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface NormalizeAimdFigureIdsResult {
|
|
37
|
+
content: string
|
|
38
|
+
changed: boolean
|
|
39
|
+
generated: GeneratedAimdFigureId[]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type PrepareAimdFormalOutputResult = NormalizeAimdFigureIdsResult
|
|
43
|
+
|
|
44
|
+
export class AimdFormalOutputError extends Error {
|
|
45
|
+
readonly issues: string[]
|
|
46
|
+
|
|
47
|
+
constructor(issues: string[]) {
|
|
48
|
+
super(issues.join('; '))
|
|
49
|
+
this.name = 'AimdFormalOutputError'
|
|
50
|
+
this.issues = issues
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface SourceLine {
|
|
55
|
+
startOffset: number
|
|
56
|
+
endOffset: number
|
|
57
|
+
textEndOffset: number
|
|
58
|
+
text: string
|
|
59
|
+
lineEnding: string
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function splitSourceLines(content: string): SourceLine[] {
|
|
63
|
+
const lines: SourceLine[] = []
|
|
64
|
+
let startOffset = 0
|
|
65
|
+
|
|
66
|
+
while (startOffset < content.length) {
|
|
67
|
+
let textEndOffset = startOffset
|
|
68
|
+
while (
|
|
69
|
+
textEndOffset < content.length
|
|
70
|
+
&& content[textEndOffset] !== '\n'
|
|
71
|
+
&& content[textEndOffset] !== '\r'
|
|
72
|
+
) {
|
|
73
|
+
textEndOffset += 1
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let endOffset = textEndOffset
|
|
77
|
+
let lineEnding = ''
|
|
78
|
+
if (content[endOffset] === '\r' && content[endOffset + 1] === '\n') {
|
|
79
|
+
endOffset += 2
|
|
80
|
+
lineEnding = '\r\n'
|
|
81
|
+
}
|
|
82
|
+
else if (content[endOffset] === '\r' || content[endOffset] === '\n') {
|
|
83
|
+
lineEnding = content[endOffset]
|
|
84
|
+
endOffset += 1
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
lines.push({
|
|
88
|
+
startOffset,
|
|
89
|
+
endOffset,
|
|
90
|
+
textEndOffset,
|
|
91
|
+
text: content.slice(startOffset, textEndOffset),
|
|
92
|
+
lineEnding,
|
|
93
|
+
})
|
|
94
|
+
startOffset = endOffset
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return lines
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function getFenceOpening(line: string): { indentation: string, marker: string, language: string } | null {
|
|
101
|
+
const match = line.match(/^([ \t]{0,3})(`{3,}|~{3,})[ \t]*([^ \t]*)[^\r\n]*$/)
|
|
102
|
+
if (!match) return null
|
|
103
|
+
return {
|
|
104
|
+
indentation: match[1],
|
|
105
|
+
marker: match[2],
|
|
106
|
+
language: match[3].trim().toLowerCase(),
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function isMatchingFenceClose(line: string, openingMarker: string): boolean {
|
|
111
|
+
const match = line.match(/^[ \t]{0,3}(`{3,}|~{3,})[ \t]*$/)
|
|
112
|
+
return Boolean(
|
|
113
|
+
match
|
|
114
|
+
&& match[1][0] === openingMarker[0]
|
|
115
|
+
&& match[1].length >= openingMarker.length,
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function stripYamlComment(value: string): string {
|
|
120
|
+
let quote: '"' | "'" | null = null
|
|
121
|
+
let escaped = false
|
|
122
|
+
|
|
123
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
124
|
+
const char = value[index]
|
|
125
|
+
if (escaped) {
|
|
126
|
+
escaped = false
|
|
127
|
+
continue
|
|
128
|
+
}
|
|
129
|
+
if (quote) {
|
|
130
|
+
if (char === '\\' && quote === '"') {
|
|
131
|
+
escaped = true
|
|
132
|
+
}
|
|
133
|
+
else if (char === quote) {
|
|
134
|
+
quote = null
|
|
135
|
+
}
|
|
136
|
+
continue
|
|
137
|
+
}
|
|
138
|
+
if (char === '"' || char === "'") {
|
|
139
|
+
quote = char
|
|
140
|
+
continue
|
|
141
|
+
}
|
|
142
|
+
if (char === '#' && (index === 0 || /\s/.test(value[index - 1]))) {
|
|
143
|
+
return value.slice(0, index)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return value
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function parseScalarValue(rawValue: string): string {
|
|
151
|
+
const value = stripYamlComment(rawValue).trim()
|
|
152
|
+
if (!value) return ''
|
|
153
|
+
|
|
154
|
+
if (value.startsWith('"') && value.endsWith('"')) {
|
|
155
|
+
try {
|
|
156
|
+
const parsed = JSON.parse(value)
|
|
157
|
+
return typeof parsed === 'string' ? parsed : value
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
return value.slice(1, -1)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (value.startsWith("'") && value.endsWith("'")) {
|
|
164
|
+
return value.slice(1, -1).replace(/''/g, "'")
|
|
165
|
+
}
|
|
166
|
+
return value
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function parseFigureField(line: SourceLine): { key: 'id' | 'src', field: AimdFigureSourceField } | null {
|
|
170
|
+
const match = line.text.match(/^([ \t]*)(id|src)[ \t]*:[ \t]*(.*)$/i)
|
|
171
|
+
if (!match) return null
|
|
172
|
+
return {
|
|
173
|
+
key: match[2].toLowerCase() as 'id' | 'src',
|
|
174
|
+
field: {
|
|
175
|
+
value: parseScalarValue(match[3]),
|
|
176
|
+
lineStartOffset: line.startOffset,
|
|
177
|
+
lineEndOffset: line.textEndOffset,
|
|
178
|
+
indentation: match[1],
|
|
179
|
+
},
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function scanAimdFigureBlocks(content: string): AimdFigureBlockInfo[] {
|
|
184
|
+
const lines = splitSourceLines(content)
|
|
185
|
+
const blocks: AimdFigureBlockInfo[] = []
|
|
186
|
+
|
|
187
|
+
for (let index = 0; index < lines.length;) {
|
|
188
|
+
const opening = getFenceOpening(lines[index].text)
|
|
189
|
+
if (!opening) {
|
|
190
|
+
index += 1
|
|
191
|
+
continue
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
let closingIndex = index + 1
|
|
195
|
+
while (
|
|
196
|
+
closingIndex < lines.length
|
|
197
|
+
&& !isMatchingFenceClose(lines[closingIndex].text, opening.marker)
|
|
198
|
+
) {
|
|
199
|
+
closingIndex += 1
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (closingIndex >= lines.length) {
|
|
203
|
+
break
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (opening.language === 'fig') {
|
|
207
|
+
let id: AimdFigureSourceField | undefined
|
|
208
|
+
let src: AimdFigureSourceField | undefined
|
|
209
|
+
for (let bodyIndex = index + 1; bodyIndex < closingIndex; bodyIndex += 1) {
|
|
210
|
+
const parsedField = parseFigureField(lines[bodyIndex])
|
|
211
|
+
if (parsedField?.key === 'id') id = parsedField.field
|
|
212
|
+
if (parsedField?.key === 'src') src = parsedField.field
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
blocks.push({
|
|
216
|
+
startOffset: lines[index].startOffset,
|
|
217
|
+
endOffset: lines[closingIndex].textEndOffset,
|
|
218
|
+
bodyStartOffset: lines[index].endOffset,
|
|
219
|
+
bodyEndOffset: lines[closingIndex].startOffset,
|
|
220
|
+
indentation: opening.indentation,
|
|
221
|
+
lineEnding: lines[index].lineEnding,
|
|
222
|
+
id,
|
|
223
|
+
src,
|
|
224
|
+
})
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
index = closingIndex + 1
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return blocks
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function stableHash(value: string): string {
|
|
234
|
+
let hash = 0x811c9dc5
|
|
235
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
236
|
+
hash ^= value.charCodeAt(index)
|
|
237
|
+
hash = Math.imul(hash, 0x01000193)
|
|
238
|
+
}
|
|
239
|
+
return (hash >>> 0).toString(16).padStart(8, '0').slice(0, 6)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function getFigureSourceStem(src: string): string {
|
|
243
|
+
let candidate = src.trim()
|
|
244
|
+
try {
|
|
245
|
+
const url = new URL(candidate)
|
|
246
|
+
candidate = url.pathname
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
candidate = candidate.split(/[?#]/, 1)[0]
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const lastSegment = candidate.replace(/\\/g, '/').split('/').filter(Boolean).pop() ?? ''
|
|
253
|
+
let decodedSegment = lastSegment
|
|
254
|
+
try {
|
|
255
|
+
decodedSegment = decodeURIComponent(lastSegment)
|
|
256
|
+
}
|
|
257
|
+
catch {}
|
|
258
|
+
|
|
259
|
+
const lastDot = decodedSegment.lastIndexOf('.')
|
|
260
|
+
return lastDot > 0 ? decodedSegment.slice(0, lastDot) : decodedSegment
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export function createAimdFigureId(src: string, usedIds: Iterable<string> = []): string {
|
|
264
|
+
let base = getFigureSourceStem(src)
|
|
265
|
+
.normalize('NFKD')
|
|
266
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
267
|
+
.replace(/[^A-Za-z0-9_]+/g, '_')
|
|
268
|
+
.replace(/^_+|_+$/g, '')
|
|
269
|
+
.toLowerCase()
|
|
270
|
+
|
|
271
|
+
if (!base) {
|
|
272
|
+
base = `fig_${stableHash(src || 'figure')}`
|
|
273
|
+
}
|
|
274
|
+
else if (/^[0-9]/.test(base)) {
|
|
275
|
+
base = `fig_${base}`
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const used = new Set(usedIds)
|
|
279
|
+
let id = base
|
|
280
|
+
let suffix = 2
|
|
281
|
+
while (used.has(id)) {
|
|
282
|
+
id = `${base}_${suffix}`
|
|
283
|
+
suffix += 1
|
|
284
|
+
}
|
|
285
|
+
return id
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export function collectAimdFigureIds(content: string): string[] {
|
|
289
|
+
return scanAimdFigureBlocks(content)
|
|
290
|
+
.map(block => block.id?.value ?? '')
|
|
291
|
+
.filter(Boolean)
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function detectPreferredLineEnding(content: string): string {
|
|
295
|
+
return content.includes('\r\n') ? '\r\n' : '\n'
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function createFigureIdEdit(
|
|
299
|
+
content: string,
|
|
300
|
+
block: AimdFigureBlockInfo,
|
|
301
|
+
id: string,
|
|
302
|
+
): AimdTextEdit {
|
|
303
|
+
if (block.id) {
|
|
304
|
+
return {
|
|
305
|
+
startOffset: block.id.lineStartOffset,
|
|
306
|
+
endOffset: block.id.lineEndOffset,
|
|
307
|
+
text: `${block.id.indentation}id: ${id}`,
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const lineEnding = block.lineEnding || detectPreferredLineEnding(content)
|
|
312
|
+
return {
|
|
313
|
+
startOffset: block.bodyStartOffset,
|
|
314
|
+
endOffset: block.bodyStartOffset,
|
|
315
|
+
text: `${block.src?.indentation ?? block.indentation}id: ${id}${lineEnding}`,
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function applyTextEdits(content: string, edits: AimdTextEdit[]): string {
|
|
320
|
+
return [...edits]
|
|
321
|
+
.sort((left, right) => right.startOffset - left.startOffset)
|
|
322
|
+
.reduce(
|
|
323
|
+
(result, edit) => `${result.slice(0, edit.startOffset)}${edit.text}${result.slice(edit.endOffset)}`,
|
|
324
|
+
content,
|
|
325
|
+
)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export function normalizeAimdFigureIds(content: string): NormalizeAimdFigureIdsResult {
|
|
329
|
+
const blocks = scanAimdFigureBlocks(content)
|
|
330
|
+
const usedIds = new Set(
|
|
331
|
+
blocks.map(block => block.id?.value ?? '').filter(Boolean),
|
|
332
|
+
)
|
|
333
|
+
const generated: GeneratedAimdFigureId[] = []
|
|
334
|
+
|
|
335
|
+
for (const block of blocks) {
|
|
336
|
+
const src = block.src?.value ?? ''
|
|
337
|
+
if (block.id?.value || !src) continue
|
|
338
|
+
|
|
339
|
+
const id = createAimdFigureId(src, usedIds)
|
|
340
|
+
usedIds.add(id)
|
|
341
|
+
generated.push({
|
|
342
|
+
id,
|
|
343
|
+
src,
|
|
344
|
+
blockStartOffset: block.startOffset,
|
|
345
|
+
edit: createFigureIdEdit(content, block, id),
|
|
346
|
+
})
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const normalizedContent = applyTextEdits(content, generated.map(item => item.edit))
|
|
350
|
+
return {
|
|
351
|
+
content: normalizedContent,
|
|
352
|
+
changed: generated.length > 0,
|
|
353
|
+
generated,
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export function prepareAimdForFormalOutput(content: string): PrepareAimdFormalOutputResult {
|
|
358
|
+
const normalized = normalizeAimdFigureIds(content)
|
|
359
|
+
const figures = scanAimdFigureBlocks(normalized.content).map(block => ({
|
|
360
|
+
id: block.id?.value,
|
|
361
|
+
src: block.src?.value,
|
|
362
|
+
}))
|
|
363
|
+
const issues = validateFigDefinitions(figures)
|
|
364
|
+
if (issues.length > 0) {
|
|
365
|
+
throw new AimdFormalOutputError(issues)
|
|
366
|
+
}
|
|
367
|
+
return normalized
|
|
368
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export {
|
|
2
|
+
AIMD_FIG_ID_PATTERN,
|
|
3
|
+
AimdFormalOutputError,
|
|
4
|
+
collectAimdFigureIds,
|
|
5
|
+
createAimdFigureId,
|
|
6
|
+
normalizeAimdFigureIds,
|
|
7
|
+
prepareAimdForFormalOutput,
|
|
8
|
+
scanAimdFigureBlocks,
|
|
9
|
+
type AimdFigureBlockInfo,
|
|
10
|
+
type AimdFigureSourceField,
|
|
11
|
+
type AimdTextEdit,
|
|
12
|
+
type GeneratedAimdFigureId,
|
|
13
|
+
type NormalizeAimdFigureIdsResult,
|
|
14
|
+
type PrepareAimdFormalOutputResult,
|
|
15
|
+
} from './fig'
|
package/src/index.ts
CHANGED
package/src/language-config.ts
CHANGED
|
@@ -12,7 +12,7 @@ const surroundingPairs = autoClosingPairs
|
|
|
12
12
|
function getTokens(tokens: string, divider = "|"): string[] {
|
|
13
13
|
return tokens.split(divider)
|
|
14
14
|
}
|
|
15
|
-
const keywords: string[] = getTokens("var|var_table|check|step|ref_step|ref_var|ref_fig|ref_media|ref_table|table_link")
|
|
15
|
+
const keywords: string[] = getTokens("var|var_table|check|step|ref_step|ref_var|ref_fig|ref_media|ref_table|table_link|workflow|connectors|collectors")
|
|
16
16
|
|
|
17
17
|
export const language: languagesNS.IMonarchLanguage = {
|
|
18
18
|
...markdownLanguage,
|
|
@@ -26,6 +26,21 @@ export const language: languagesNS.IMonarchLanguage = {
|
|
|
26
26
|
next: "@quizCodeblock",
|
|
27
27
|
nextEmbedded: "yaml",
|
|
28
28
|
}],
|
|
29
|
+
[/^\s*(```|~~~)\s*workflow(?:\s+.*)?\s*$/, {
|
|
30
|
+
token: "string",
|
|
31
|
+
next: "@quizCodeblock",
|
|
32
|
+
nextEmbedded: "yaml",
|
|
33
|
+
}],
|
|
34
|
+
[/^\s*(```|~~~)\s*connectors(?:\s+.*)?\s*$/, {
|
|
35
|
+
token: "string",
|
|
36
|
+
next: "@quizCodeblock",
|
|
37
|
+
nextEmbedded: "yaml",
|
|
38
|
+
}],
|
|
39
|
+
[/^\s*(```|~~~)\s*collectors(?:\s+.*)?\s*$/, {
|
|
40
|
+
token: "string",
|
|
41
|
+
next: "@quizCodeblock",
|
|
42
|
+
nextEmbedded: "yaml",
|
|
43
|
+
}],
|
|
29
44
|
[/^\s*(```|~~~)\s*(fig|media)(?:\s+.*)?\s*$/, {
|
|
30
45
|
token: "string",
|
|
31
46
|
next: "@quizCodeblock",
|