@agentshouse/mdmodel 0.1.0-alpha.9 → 0.1.0-c83456e1cebfb
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/API.md +298 -0
- package/README.md +29 -186
- package/dist/blocks.d.ts +11 -0
- package/dist/blocks.d.ts.map +1 -0
- package/dist/blocks.js +62 -0
- package/dist/definition.d.ts +7 -3
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +143 -134
- package/dist/divide.d.ts +3 -0
- package/dist/divide.d.ts.map +1 -0
- package/dist/divide.js +310 -0
- package/dist/document.d.ts +2 -0
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +89 -120
- package/dist/fields.d.ts +4 -0
- package/dist/fields.d.ts.map +1 -0
- package/dist/fields.js +3 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/links.d.ts +1 -0
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +618 -224
- package/dist/paths.d.ts +2 -3
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +27 -37
- package/dist/profile.js +1 -3
- package/dist/project.d.ts +19 -1
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +75 -91
- package/dist/refuse.d.ts.map +1 -1
- package/dist/refuse.js +2 -10
- package/dist/schema.d.ts +2 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +22 -33
- package/dist/sections.d.ts +2 -1
- package/dist/sections.d.ts.map +1 -1
- package/dist/sections.js +44 -66
- package/dist/types.d.ts +30 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -3
- package/dist/validate.d.ts +3 -2
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +145 -127
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -3
- package/dist/yaml.d.ts +1 -0
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +195 -186
- package/fixtures/README.md +77 -53
- package/fixtures/cases/binary-any-reference/expected.json +0 -1
- package/fixtures/cases/binary-any-reference/schema.yaml +4 -0
- package/fixtures/cases/binary-document-collision/expected.json +1 -2
- package/fixtures/cases/binary-document-collision/schema.yaml +2 -0
- package/fixtures/cases/binary-link-outside-collection/expected.json +1 -2
- package/fixtures/cases/binary-link-outside-collection/schema.yaml +2 -0
- package/fixtures/cases/binary-prototype-reference/expected.json +0 -1
- package/fixtures/cases/binary-prototype-reference/schema.yaml +4 -0
- package/fixtures/cases/binary-typed-reference/expected.json +0 -1
- package/fixtures/cases/binary-typed-reference/schema.yaml +5 -0
- package/fixtures/cases/bracketed-link-definition/schema.yaml +6 -0
- package/fixtures/cases/declared-binary-links/schema.yaml +2 -0
- package/fixtures/cases/duplicate-link-definition/schema.yaml +6 -0
- package/fixtures/cases/fenced-link-definition/schema.yaml +6 -0
- package/fixtures/cases/field-enum/expected.json +1 -2
- package/fixtures/cases/field-enum/schema.yaml +7 -0
- package/fixtures/cases/frontmatter-schema/expected.json +5 -0
- package/fixtures/cases/frontmatter-schema/schema.yaml +6 -0
- package/fixtures/cases/interrupted-link-definition/schema.yaml +2 -0
- package/fixtures/cases/long-fence-link-definition/schema.yaml +2 -0
- package/fixtures/cases/malformed-definition/expected.json +2 -4
- package/fixtures/cases/malformed-definition/schema.yaml +4 -0
- package/fixtures/cases/member-document/context.json +1 -0
- package/fixtures/cases/member-document/library/people/ana.md +5 -0
- package/fixtures/cases/member-document/schema.yaml +5 -0
- package/fixtures/cases/missing-binary-image/expected.json +1 -2
- package/fixtures/cases/missing-binary-image/schema.yaml +2 -0
- package/fixtures/cases/missing-binary-link/expected.json +1 -2
- package/fixtures/cases/missing-binary-link/schema.yaml +2 -0
- package/fixtures/cases/missing-required-field/expected.json +1 -2
- package/fixtures/cases/missing-required-field/schema.yaml +7 -0
- package/fixtures/cases/missing-section-item-kind/expected.json +2 -4
- package/fixtures/cases/missing-section-item-kind/schema.yaml +6 -0
- package/fixtures/cases/paragraph-link-definition/schema.yaml +2 -0
- package/fixtures/cases/prototype-field/expected.json +1 -2
- package/fixtures/cases/prototype-field/schema.yaml +6 -0
- package/fixtures/cases/quoted-link-definition/expected.json +1 -2
- package/fixtures/cases/quoted-link-definition/schema.yaml +2 -0
- package/fixtures/cases/referenced-missing-file/expected.json +0 -1
- package/fixtures/cases/referenced-missing-file/schema.yaml +10 -0
- package/fixtures/cases/second-member-document/context.json +1 -0
- package/fixtures/cases/second-member-document/expected.json +5 -0
- package/fixtures/cases/second-member-document/schema.yaml +5 -0
- package/fixtures/cases/section-item-enum/context.json +1 -0
- package/fixtures/cases/section-item-enum/expected.json +6 -0
- package/fixtures/cases/section-item-enum/library/task.md +8 -0
- package/fixtures/cases/section-item-enum/schema.yaml +4 -0
- package/fixtures/cases/section-item-kind/context.json +1 -0
- package/fixtures/cases/section-item-kind/expected.json +6 -0
- package/fixtures/cases/section-item-kind/library/task.md +8 -0
- package/fixtures/cases/section-item-kind/schema.yaml +4 -0
- package/fixtures/cases/section-items/context.json +1 -0
- package/fixtures/cases/section-items/expected.json +1 -0
- package/fixtures/cases/section-items/library/other.md +3 -0
- package/fixtures/cases/section-items/library/page.md +28 -0
- package/fixtures/cases/section-items/schema.yaml +8 -0
- package/fixtures/cases/section-reference-path/context.json +1 -0
- package/fixtures/cases/section-reference-path/expected.json +6 -0
- package/fixtures/cases/section-reference-path/library/other.md +3 -0
- package/fixtures/cases/section-reference-path/library/page.md +7 -0
- package/fixtures/cases/section-reference-path/schema.yaml +4 -0
- package/fixtures/cases/section-reference-type/context.json +1 -0
- package/fixtures/cases/section-reference-type/expected.json +6 -0
- package/fixtures/cases/section-reference-type/library/note.md +1 -0
- package/fixtures/cases/section-reference-type/library/page.md +7 -0
- package/fixtures/cases/section-reference-type/schema.yaml +4 -0
- package/fixtures/cases/shortcut-reference-link/context.json +1 -0
- package/fixtures/cases/shortcut-reference-link/expected.json +5 -0
- package/fixtures/cases/shortcut-reference-link/library/item.md +10 -0
- package/fixtures/cases/shortcut-reference-link/schema.yaml +6 -0
- package/fixtures/cases/structured-section/expected.json +1 -2
- package/fixtures/cases/structured-section/schema.yaml +7 -0
- package/fixtures/cases/submission-keys/context.json +1 -0
- package/fixtures/cases/submission-keys/expected.json +1 -0
- package/fixtures/cases/submission-keys/library/notes/visitor.md +8 -0
- package/fixtures/cases/submission-keys/schema.yaml +4 -0
- package/fixtures/cases/text-field-kind/context.json +1 -0
- package/fixtures/cases/text-field-kind/expected.json +6 -0
- package/fixtures/cases/text-field-kind/library/page.md +4 -0
- package/fixtures/cases/text-field-kind/schema.yaml +4 -0
- package/fixtures/cases/truncated-link-definition/expected.json +1 -2
- package/fixtures/cases/truncated-link-definition/schema.yaml +2 -0
- package/fixtures/cases/types-folder-content/context.json +1 -0
- package/fixtures/cases/types-folder-content/expected.json +1 -0
- package/fixtures/cases/types-folder-content/library/types/task.md +4 -0
- package/fixtures/cases/types-folder-content/schema.yaml +4 -0
- package/fixtures/cases/unclosed-frontmatter/expected.json +1 -2
- package/fixtures/cases/undeclared-field/expected.json +1 -2
- package/fixtures/cases/undeclared-field/schema.yaml +6 -0
- package/fixtures/cases/unknown-type/context.json +1 -0
- package/fixtures/cases/unknown-type/expected.json +6 -0
- package/fixtures/cases/unknown-type/library/item.md +3 -0
- package/fixtures/cases/unknown-type/schema.yaml +4 -0
- package/fixtures/cases/unlisted-reference-type/context.json +1 -0
- package/fixtures/cases/unlisted-reference-type/expected.json +5 -0
- package/fixtures/cases/unlisted-reference-type/schema.yaml +4 -0
- package/fixtures/cases/unresolved-link/expected.json +1 -2
- package/fixtures/cases/unresolved-link/schema.yaml +6 -0
- package/fixtures/cases/valid-typed-document/schema.yaml +15 -0
- package/fixtures/cases/wide-item-fence-link/schema.yaml +2 -0
- package/fixtures/division.json +409 -0
- package/fixtures/projection.json +58 -21
- package/package.json +3 -12
- package/dist/definition.js.map +0 -1
- package/dist/document.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/links.js.map +0 -1
- package/dist/paths.js.map +0 -1
- package/dist/profile.js.map +0 -1
- package/dist/project.js.map +0 -1
- package/dist/refuse.js.map +0 -1
- package/dist/schema.js.map +0 -1
- package/dist/sections.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/validate.js.map +0 -1
- package/dist/version.js.map +0 -1
- package/dist/yaml.js.map +0 -1
- package/fixtures/cases/binary-any-reference/library/types/note.md +0 -5
- package/fixtures/cases/binary-document-collision/library/types/note.md +0 -3
- package/fixtures/cases/binary-link-outside-collection/library/types/note.md +0 -3
- package/fixtures/cases/binary-prototype-reference/library/types/note.md +0 -5
- package/fixtures/cases/binary-typed-reference/library/types/note.md +0 -5
- package/fixtures/cases/binary-typed-reference/library/types/person.md +0 -3
- package/fixtures/cases/bracketed-link-definition/library/types/task.md +0 -7
- package/fixtures/cases/declared-binary-links/library/types/note.md +0 -3
- package/fixtures/cases/duplicate-link-definition/library/types/task.md +0 -7
- package/fixtures/cases/fenced-link-definition/library/types/task.md +0 -7
- package/fixtures/cases/field-enum/library/types/task.md +0 -8
- package/fixtures/cases/interrupted-link-definition/library/types/note.md +0 -3
- package/fixtures/cases/long-fence-link-definition/library/types/note.md +0 -3
- package/fixtures/cases/malformed-definition/library/types/task.md +0 -5
- package/fixtures/cases/missing-binary-image/library/types/note.md +0 -3
- package/fixtures/cases/missing-binary-link/library/types/note.md +0 -3
- package/fixtures/cases/missing-required-field/library/types/task.md +0 -8
- package/fixtures/cases/missing-section-item-kind/library/types/task.md +0 -7
- package/fixtures/cases/paragraph-link-definition/library/types/note.md +0 -3
- package/fixtures/cases/prd-definition/library/types/task.md +0 -16
- package/fixtures/cases/prototype-field/library/types/task.md +0 -7
- package/fixtures/cases/quoted-link-definition/library/types/note.md +0 -3
- package/fixtures/cases/referenced-missing-file/library/types/person.md +0 -5
- package/fixtures/cases/referenced-missing-file/library/types/task.md +0 -8
- package/fixtures/cases/structured-section/library/types/task.md +0 -8
- package/fixtures/cases/truncated-link-definition/library/types/note.md +0 -3
- package/fixtures/cases/undeclared-field/library/types/task.md +0 -7
- package/fixtures/cases/unresolved-link/library/types/task.md +0 -7
- package/fixtures/cases/valid-typed-document/library/types/person.md +0 -5
- package/fixtures/cases/valid-typed-document/library/types/task.md +0 -13
- package/fixtures/cases/wide-item-fence-link/library/types/note.md +0 -3
- package/markdown-syntax-profile.md +0 -9
- /package/fixtures/cases/{prd-definition → frontmatter-schema}/context.json +0 -0
- /package/fixtures/cases/{prd-definition → member-document}/expected.json +0 -0
package/dist/document.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { hrefOccurrences } from './links.js';
|
|
2
|
-
import {
|
|
2
|
+
import { retarget, target } from './paths.js';
|
|
3
3
|
import { headingSpans, sectionsRecord } from './sections.js';
|
|
4
4
|
import { refusal } from './refuse.js';
|
|
5
|
-
import { bodyStartAfterYaml, bodyStartOf, equalValue, extractFrontmatter, jsValue, lineEnding, mapEntry, parseYamlMapping, serializeJs, serializeKey, YamlError } from './yaml.js';
|
|
5
|
+
import { bodyStartAfterYaml, bodyStartOf, equalValue, extractFrontmatter, jsValue, lineEnding, mapEntry, parseYamlMapping, serializeJs, serializeKey, YamlError, } from './yaml.js';
|
|
6
6
|
const internals = new WeakMap();
|
|
7
7
|
function refuse(file, rule, location) {
|
|
8
|
-
return location === undefined ? refusal(file, rule) : refusal(file, rule, {
|
|
9
|
-
location
|
|
10
|
-
});
|
|
8
|
+
return location === undefined ? refusal(file, rule) : refusal(file, rule, { location });
|
|
11
9
|
}
|
|
12
10
|
function freezeDocument(content, type, fields, preamble, sections, internal) {
|
|
13
11
|
const document = Object.freeze({
|
|
@@ -15,15 +13,17 @@ function freezeDocument(content, type, fields, preamble, sections, internal) {
|
|
|
15
13
|
type,
|
|
16
14
|
fields: Object.freeze(fields),
|
|
17
15
|
preamble,
|
|
18
|
-
sections: Object.freeze(sections)
|
|
16
|
+
sections: Object.freeze(sections),
|
|
19
17
|
});
|
|
20
18
|
internals.set(document, internal);
|
|
21
19
|
return document;
|
|
22
20
|
}
|
|
23
21
|
function declaredType(fields) {
|
|
24
22
|
const value = fields.type;
|
|
25
|
-
if (value === undefined || value === null)
|
|
26
|
-
|
|
23
|
+
if (value === undefined || value === null)
|
|
24
|
+
return undefined;
|
|
25
|
+
if (typeof value !== 'string' || value === '')
|
|
26
|
+
return undefined;
|
|
27
27
|
return value;
|
|
28
28
|
}
|
|
29
29
|
export function parse(content, file = '') {
|
|
@@ -35,22 +35,17 @@ export function parse(content, file = '') {
|
|
|
35
35
|
document: freezeDocument(content, undefined, {}, content.slice(0, spans[0]?.headingStart), sectionsRecord(spans, content), {
|
|
36
36
|
root: null,
|
|
37
37
|
yamlEnd: 0,
|
|
38
|
-
bodyStart: 0
|
|
39
|
-
})
|
|
38
|
+
bodyStart: 0,
|
|
39
|
+
}),
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
if (fence.kind === 'unclosed')
|
|
43
|
-
ok: false,
|
|
44
|
-
refusal: refuse(file, 'frontmatter-fence')
|
|
45
|
-
};
|
|
42
|
+
if (fence.kind === 'unclosed')
|
|
43
|
+
return { ok: false, refusal: refuse(file, 'frontmatter-fence') };
|
|
46
44
|
try {
|
|
47
45
|
const root = parseYamlMapping(content, fence.yamlStart, fence.yamlEnd);
|
|
48
46
|
const fields = jsValue(root);
|
|
49
47
|
if (fields === null || typeof fields !== 'object' || Array.isArray(fields)) {
|
|
50
|
-
return {
|
|
51
|
-
ok: false,
|
|
52
|
-
refusal: refuse(file, 'frontmatter-fence')
|
|
53
|
-
};
|
|
48
|
+
return { ok: false, refusal: refuse(file, 'frontmatter-fence') };
|
|
54
49
|
}
|
|
55
50
|
const bodyStart = bodyStartAfterYaml(content, fence.yamlEnd);
|
|
56
51
|
const spans = headingSpans(content, bodyStart);
|
|
@@ -60,14 +55,13 @@ export function parse(content, file = '') {
|
|
|
60
55
|
document: freezeDocument(content, declaredType(record), record, content.slice(bodyStart, spans[0]?.headingStart), sectionsRecord(spans, content), {
|
|
61
56
|
root,
|
|
62
57
|
yamlEnd: fence.yamlEnd,
|
|
63
|
-
bodyStart
|
|
64
|
-
})
|
|
65
|
-
};
|
|
66
|
-
} catch (error) {
|
|
67
|
-
if (error instanceof YamlError) return {
|
|
68
|
-
ok: false,
|
|
69
|
-
refusal: refuse(file, 'frontmatter-fence')
|
|
58
|
+
bodyStart,
|
|
59
|
+
}),
|
|
70
60
|
};
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (error instanceof YamlError)
|
|
64
|
+
return { ok: false, refusal: refuse(file, 'frontmatter-fence') };
|
|
71
65
|
throw error;
|
|
72
66
|
}
|
|
73
67
|
}
|
|
@@ -77,89 +71,70 @@ function splice(content, start, end, insert) {
|
|
|
77
71
|
function applyField(document, name, value, prior) {
|
|
78
72
|
const internal = internals.get(document);
|
|
79
73
|
if (internal === undefined || internal.root === null) {
|
|
80
|
-
return {
|
|
81
|
-
outcome: 'refuse',
|
|
82
|
-
refusal: refuse('', 'frontmatter-fence', name)
|
|
83
|
-
};
|
|
74
|
+
return { outcome: 'refuse', refusal: refuse('', 'frontmatter-fence', name) };
|
|
84
75
|
}
|
|
85
76
|
if (!equalValue(document.fields[name], prior)) {
|
|
86
|
-
return {
|
|
87
|
-
outcome: 'stale',
|
|
88
|
-
document
|
|
89
|
-
};
|
|
77
|
+
return { outcome: 'stale', document };
|
|
90
78
|
}
|
|
91
79
|
let nextContent;
|
|
92
80
|
const existing = mapEntry(internal.root, name);
|
|
93
81
|
if (existing !== undefined) {
|
|
94
82
|
nextContent = splice(document.content, existing.value.start, existing.value.end, serializeJs(value));
|
|
95
|
-
}
|
|
83
|
+
}
|
|
84
|
+
else if (document.content[internal.root.start] === '{') {
|
|
85
|
+
nextContent = splice(document.content, internal.root.end - 1, internal.root.end - 1, `${internal.root.entries.length === 0 ? '' : ', '}${serializeKey(name)}: ${serializeJs(value)}`);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
96
88
|
const nl = lineEnding(document.content);
|
|
97
|
-
const
|
|
89
|
+
const lineStart = document.content.lastIndexOf('\n', internal.root.start - 1) + 1;
|
|
90
|
+
const indent = document.content.slice(lineStart, internal.root.start);
|
|
91
|
+
const line = `${indent}${serializeKey(name)}: ${serializeJs(value)}${nl}`;
|
|
98
92
|
const before = document.content.slice(0, internal.yamlEnd);
|
|
99
93
|
const prefix = before.endsWith('\n') || before.endsWith('\r\n') ? '' : nl;
|
|
100
94
|
nextContent = splice(document.content, internal.yamlEnd, internal.yamlEnd, `${prefix}${line}`);
|
|
101
95
|
}
|
|
102
96
|
const parsed = parse(nextContent);
|
|
103
|
-
if (!parsed.ok)
|
|
104
|
-
outcome: 'refuse',
|
|
105
|
-
|
|
106
|
-
};
|
|
107
|
-
return {
|
|
108
|
-
outcome: 'applied',
|
|
109
|
-
document: parsed.document
|
|
110
|
-
};
|
|
97
|
+
if (!parsed.ok)
|
|
98
|
+
return { outcome: 'refuse', refusal: parsed.refusal };
|
|
99
|
+
return { outcome: 'applied', document: parsed.document };
|
|
111
100
|
}
|
|
112
101
|
function applySection(document, name, value, prior) {
|
|
113
102
|
const internal = internals.get(document);
|
|
114
|
-
if (internal === undefined)
|
|
115
|
-
outcome: 'refuse',
|
|
116
|
-
refusal: refuse('', 'required-section', name)
|
|
117
|
-
};
|
|
103
|
+
if (internal === undefined)
|
|
104
|
+
return { outcome: 'refuse', refusal: refuse('', 'required-section', name) };
|
|
118
105
|
const spans = headingSpans(document.content, internal.bodyStart);
|
|
119
|
-
const span = spans.find((item)=>item.name === name);
|
|
120
|
-
if (span === undefined)
|
|
121
|
-
outcome: 'refuse',
|
|
122
|
-
refusal: refuse('', 'required-section', name)
|
|
123
|
-
};
|
|
106
|
+
const span = spans.find((item) => item.name === name);
|
|
107
|
+
if (span === undefined)
|
|
108
|
+
return { outcome: 'refuse', refusal: refuse('', 'required-section', name) };
|
|
124
109
|
const current = document.content.slice(span.bodyStart, span.bodyEnd);
|
|
125
|
-
if (current !== prior)
|
|
126
|
-
outcome: 'stale',
|
|
127
|
-
document
|
|
128
|
-
};
|
|
110
|
+
if (current !== prior)
|
|
111
|
+
return { outcome: 'stale', document };
|
|
129
112
|
const parsed = parse(splice(document.content, span.bodyStart, span.bodyEnd, value));
|
|
130
|
-
if (!parsed.ok)
|
|
131
|
-
outcome: 'refuse',
|
|
132
|
-
|
|
133
|
-
};
|
|
134
|
-
return {
|
|
135
|
-
outcome: 'applied',
|
|
136
|
-
document: parsed.document
|
|
137
|
-
};
|
|
113
|
+
if (!parsed.ok)
|
|
114
|
+
return { outcome: 'refuse', refusal: parsed.refusal };
|
|
115
|
+
return { outcome: 'applied', document: parsed.document };
|
|
138
116
|
}
|
|
139
117
|
function applyPreamble(document, value, prior) {
|
|
140
|
-
if (document.preamble !== prior)
|
|
141
|
-
outcome: 'stale',
|
|
142
|
-
document
|
|
143
|
-
};
|
|
118
|
+
if (document.preamble !== prior)
|
|
119
|
+
return { outcome: 'stale', document };
|
|
144
120
|
const start = bodyStartOf(document.content);
|
|
145
121
|
const parsed = parse(splice(document.content, start, start + document.preamble.length, value));
|
|
146
|
-
if (!parsed.ok)
|
|
147
|
-
outcome: 'refuse',
|
|
148
|
-
|
|
149
|
-
};
|
|
150
|
-
return {
|
|
151
|
-
outcome: 'applied',
|
|
152
|
-
document: parsed.document
|
|
153
|
-
};
|
|
122
|
+
if (!parsed.ok)
|
|
123
|
+
return { outcome: 'refuse', refusal: parsed.refusal };
|
|
124
|
+
return { outcome: 'applied', document: parsed.document };
|
|
154
125
|
}
|
|
155
126
|
function fitsBare(to) {
|
|
156
|
-
if (to === '' || to.startsWith('<'))
|
|
127
|
+
if (to === '' || to.startsWith('<'))
|
|
128
|
+
return false;
|
|
157
129
|
let depth = 0;
|
|
158
|
-
for (const character of to){
|
|
159
|
-
if (/[\s\u0000-\u001f\u007f]/.test(character))
|
|
160
|
-
|
|
130
|
+
for (const character of to) {
|
|
131
|
+
if (/[\s\u0000-\u001f\u007f]/.test(character))
|
|
132
|
+
return false;
|
|
133
|
+
if (character === '(')
|
|
134
|
+
depth += 1;
|
|
161
135
|
else if (character === ')') {
|
|
162
|
-
if (depth === 0)
|
|
136
|
+
if (depth === 0)
|
|
137
|
+
return false;
|
|
163
138
|
depth -= 1;
|
|
164
139
|
}
|
|
165
140
|
}
|
|
@@ -169,68 +144,61 @@ function fitsBrackets(to) {
|
|
|
169
144
|
return to !== '' && !/[<>\n\r]/.test(to);
|
|
170
145
|
}
|
|
171
146
|
function destinationText(to, bracketed) {
|
|
172
|
-
if (fitsBare(to))
|
|
173
|
-
|
|
147
|
+
if (fitsBare(to))
|
|
148
|
+
return bracketed && fitsBrackets(to) ? `<${to}>` : to;
|
|
149
|
+
if (fitsBrackets(to))
|
|
150
|
+
return `<${to}>`;
|
|
174
151
|
return null;
|
|
175
152
|
}
|
|
176
153
|
function applyLink(document, href, to) {
|
|
177
154
|
const content = document.content;
|
|
178
155
|
const bodyStart = bodyStartOf(content);
|
|
179
|
-
const matches = hrefOccurrences(content.slice(bodyStart)).filter((occurrence)=>occurrence.href === href);
|
|
180
|
-
if (matches.length === 0)
|
|
181
|
-
outcome: 'stale',
|
|
182
|
-
|
|
183
|
-
};
|
|
184
|
-
const written = to + hrefSuffix(href);
|
|
156
|
+
const matches = hrefOccurrences(content.slice(bodyStart)).filter((occurrence) => occurrence.href === href);
|
|
157
|
+
if (matches.length === 0)
|
|
158
|
+
return { outcome: 'stale', document };
|
|
159
|
+
const written = retarget(href, to);
|
|
185
160
|
let rewritten = '';
|
|
186
161
|
let cursor = 0;
|
|
187
|
-
for (const match of matches){
|
|
162
|
+
for (const match of matches) {
|
|
188
163
|
const text = destinationText(written, match.bracketed);
|
|
189
|
-
if (text === null)
|
|
190
|
-
outcome: 'refuse',
|
|
191
|
-
refusal: refuse('', 'unwritable-link', written)
|
|
192
|
-
};
|
|
164
|
+
if (text === null)
|
|
165
|
+
return { outcome: 'refuse', refusal: refuse('', 'unwritable-link', written) };
|
|
193
166
|
rewritten += content.slice(cursor, bodyStart + match.start);
|
|
194
167
|
rewritten += text;
|
|
195
168
|
cursor = bodyStart + match.end;
|
|
196
169
|
}
|
|
197
170
|
const parsed = parse(rewritten + content.slice(cursor));
|
|
198
|
-
if (!parsed.ok)
|
|
199
|
-
outcome: 'refuse',
|
|
200
|
-
|
|
201
|
-
};
|
|
202
|
-
return {
|
|
203
|
-
outcome: 'applied',
|
|
204
|
-
document: parsed.document
|
|
205
|
-
};
|
|
171
|
+
if (!parsed.ok)
|
|
172
|
+
return { outcome: 'refuse', refusal: parsed.refusal };
|
|
173
|
+
return { outcome: 'applied', document: parsed.document };
|
|
206
174
|
}
|
|
207
175
|
export function links(document, file) {
|
|
208
176
|
const found = [];
|
|
209
177
|
const seen = new Set();
|
|
210
|
-
for (const occurrence of hrefOccurrences(document.content.slice(bodyStartOf(document.content)))){
|
|
211
|
-
if (seen.has(occurrence.href))
|
|
212
|
-
|
|
213
|
-
|
|
178
|
+
for (const occurrence of hrefOccurrences(document.content.slice(bodyStartOf(document.content)))) {
|
|
179
|
+
if (seen.has(occurrence.href))
|
|
180
|
+
continue;
|
|
181
|
+
const resolved = target(file, occurrence.href);
|
|
182
|
+
if (resolved === null)
|
|
183
|
+
continue;
|
|
214
184
|
seen.add(occurrence.href);
|
|
215
|
-
found.push({
|
|
216
|
-
href: occurrence.href,
|
|
217
|
-
target: resolved.path
|
|
218
|
-
});
|
|
185
|
+
found.push({ href: occurrence.href, target: resolved });
|
|
219
186
|
}
|
|
220
187
|
return found;
|
|
221
188
|
}
|
|
222
189
|
export function apply(document, change) {
|
|
223
|
-
if (change.kind === 'link')
|
|
224
|
-
|
|
190
|
+
if (change.kind === 'link')
|
|
191
|
+
return applyLink(document, change.href, change.to);
|
|
192
|
+
if (change.kind === 'preamble')
|
|
193
|
+
return applyPreamble(document, change.value, change.prior);
|
|
225
194
|
try {
|
|
226
|
-
if (change.kind === 'field')
|
|
195
|
+
if (change.kind === 'field')
|
|
196
|
+
return applyField(document, change.name, change.value, change.prior);
|
|
227
197
|
return applySection(document, change.name, change.value, change.prior);
|
|
228
|
-
}
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
229
200
|
if (error instanceof YamlError) {
|
|
230
|
-
return {
|
|
231
|
-
outcome: 'refuse',
|
|
232
|
-
refusal: refuse('', 'frontmatter-fence', change.name)
|
|
233
|
-
};
|
|
201
|
+
return { outcome: 'refuse', refusal: refuse('', 'frontmatter-fence', change.name) };
|
|
234
202
|
}
|
|
235
203
|
throw error;
|
|
236
204
|
}
|
|
@@ -238,5 +206,6 @@ export function apply(document, change) {
|
|
|
238
206
|
export function serialize(document) {
|
|
239
207
|
return document.content;
|
|
240
208
|
}
|
|
241
|
-
|
|
242
|
-
|
|
209
|
+
export function frontmatter(document) {
|
|
210
|
+
return internals.get(document)?.root ?? null;
|
|
211
|
+
}
|
package/dist/fields.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,WAAW,CAAC;AAErC,eAAO,MAAM,UAAU,SAAS,CAAC;AAEjC,eAAO,MAAM,cAAc,aAAa,CAAC"}
|
package/dist/fields.js
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
export { divide } from './divide.js';
|
|
1
2
|
export { apply, links, parse, serialize } from './document.js';
|
|
3
|
+
export { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD } from './fields.js';
|
|
4
|
+
export { retarget, target } from './paths.js';
|
|
2
5
|
export { MARKDOWN_SYNTAX_PROFILE } from './profile.js';
|
|
3
6
|
export { project } from './project.js';
|
|
4
|
-
export type {
|
|
5
|
-
export {
|
|
7
|
+
export type { Definition, FieldSpec, SectionSpec } from './definition.js';
|
|
8
|
+
export type { ApplyResult, Change, Division, DivisionContext, Document, Library, ModelVerification, Link, ParseResult, Projection, ProjectionContext, Refusal, Span, Validation, ValidationContext, VerifiedModel, } from './types.js';
|
|
9
|
+
export { validate, verify } from './validate.js';
|
|
6
10
|
export { VERSION } from './version.js';
|
|
7
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,YAAY,EACV,WAAW,EACX,MAAM,EACN,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,OAAO,EACP,UAAU,EACV,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC1E,YAAY,EACV,WAAW,EACX,MAAM,EACN,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,OAAO,EACP,iBAAiB,EACjB,IAAI,EACJ,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,OAAO,EACP,IAAI,EACJ,UAAU,EACV,iBAAiB,EACjB,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
export { divide } from './divide.js';
|
|
1
2
|
export { apply, links, parse, serialize } from './document.js';
|
|
3
|
+
export { MEMBER_FIELD, RECEIVED_FIELD, SITE_FIELD } from './fields.js';
|
|
4
|
+
export { retarget, target } from './paths.js';
|
|
2
5
|
export { MARKDOWN_SYNTAX_PROFILE } from './profile.js';
|
|
3
6
|
export { project } from './project.js';
|
|
4
|
-
export { validate } from './validate.js';
|
|
7
|
+
export { validate, verify } from './validate.js';
|
|
5
8
|
export { VERSION } from './version.js';
|
|
6
|
-
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
package/dist/links.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export type LinkInventory = {
|
|
|
20
20
|
readonly uses: readonly LinkUse[];
|
|
21
21
|
readonly blocks: readonly DefinitionBlock[];
|
|
22
22
|
};
|
|
23
|
+
export declare function fenceSpans(text: string): readonly (readonly [number, number])[];
|
|
23
24
|
export declare function linkInventory(body: string): LinkInventory;
|
|
24
25
|
export declare function hrefOccurrences(body: string): readonly HrefOccurrence[];
|
|
25
26
|
//# sourceMappingURL=links.d.ts.map
|
package/dist/links.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AA0sBA,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,cAAc,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,WAAW,EAAE,cAAc,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,CAAC;CAC7C,CAAC;AAEF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAe/E;AAYD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CA2DzD;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,cAAc,EAAE,CAIvE"}
|