@agentshouse/mdmodel 0.1.0-alpha.4 → 0.1.0-alpha.5
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 +40 -2
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +21 -3
- package/dist/document.js.map +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/fixtures/README.md +14 -0
- package/fixtures/preamble.json +107 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -76,8 +76,46 @@ a resulting collection supplies that collection's context to this same
|
|
|
76
76
|
`validate` function. `parse`, `apply`, and `serialize` operate on a single text
|
|
77
77
|
Document; they do not validate collection membership or consume binary bytes.
|
|
78
78
|
`apply` sets one typed field, including a list field as a whole, replaces
|
|
79
|
-
one
|
|
80
|
-
Markdown link destination. A
|
|
79
|
+
one existing section body or the preamble against that value's prior content,
|
|
80
|
+
or rewrites one Markdown link destination. A section need not be declared by
|
|
81
|
+
the Document's MD Type to be replaced. A field change does not reformat the rest of the file.
|
|
82
|
+
|
|
83
|
+
`Document.preamble` is a readonly string containing the exact source after
|
|
84
|
+
frontmatter and before the first section heading recognized by the existing
|
|
85
|
+
section parser. Without a section it is the entire post-frontmatter body;
|
|
86
|
+
without frontmatter it starts at the beginning of the Document. An empty span
|
|
87
|
+
is `''`. It includes whitespace, newlines, a leading H1, and any fenced text
|
|
88
|
+
before the first section. The closing frontmatter delimiter and its line ending
|
|
89
|
+
belong to frontmatter. Section recognition and the syntax profile are unchanged.
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
const parsed = parse(content);
|
|
93
|
+
if (parsed.ok) {
|
|
94
|
+
const change = {
|
|
95
|
+
kind: 'preamble' as const,
|
|
96
|
+
prior: parsed.document.preamble,
|
|
97
|
+
value: 'Updated introduction.\n\n',
|
|
98
|
+
};
|
|
99
|
+
const result = apply(parsed.document, change);
|
|
100
|
+
if (result.outcome === 'applied') serialize(result.document);
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`apply(document, { kind: 'preamble', prior, value })` compares `prior` to the
|
|
105
|
+
current preamble exactly. A mismatch returns `{ outcome: 'stale', document }`
|
|
106
|
+
with the unchanged current Document. A match replaces only that source span,
|
|
107
|
+
then parses a new immutable Document; the original is unchanged. Frontmatter
|
|
108
|
+
and section source outside the span retain their exact bytes, including newline
|
|
109
|
+
and heading syntax. As with section replacement, `value` is literal source:
|
|
110
|
+
no newline or separator is inserted, and the resulting source is parsed again.
|
|
111
|
+
An invalid frontmatter result receives the existing parse refusal. Independent
|
|
112
|
+
field, section, and preamble edits keep their own prior values valid.
|
|
113
|
+
|
|
114
|
+
For a moved link, use `links` and the `link` change below to obtain the rewritten
|
|
115
|
+
Document, then compare its public `preamble` and `sections` to the original.
|
|
116
|
+
Submit the changed values with their original priors. Consumers need no source
|
|
117
|
+
span calculation or private Model import. Collection validation remains a
|
|
118
|
+
separate call against the resulting Library.
|
|
81
119
|
|
|
82
120
|
`links(document, file)` is the inventory of that Document's ordinary link and
|
|
83
121
|
image destinations that resolve to a collection Path, each with the destination
|
package/dist/document.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAsDnF,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,SAAK,GAAG,WAAW,CAkD7D;AAyGD,wBAAgB,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,IAAI,EAAE,CAWvE;AAED,wBAAgB,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAarE;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAEpD"}
|
package/dist/document.js
CHANGED
|
@@ -9,11 +9,12 @@ function refuse(file, rule, location) {
|
|
|
9
9
|
location
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
|
-
function freezeDocument(content, type, fields, sections, internal) {
|
|
12
|
+
function freezeDocument(content, type, fields, preamble, sections, internal) {
|
|
13
13
|
const document = Object.freeze({
|
|
14
14
|
content,
|
|
15
15
|
type,
|
|
16
16
|
fields: Object.freeze(fields),
|
|
17
|
+
preamble,
|
|
17
18
|
sections: Object.freeze(sections)
|
|
18
19
|
});
|
|
19
20
|
internals.set(document, internal);
|
|
@@ -31,7 +32,7 @@ export function parse(content, file = '') {
|
|
|
31
32
|
const spans = headingSpans(content, 0);
|
|
32
33
|
return {
|
|
33
34
|
ok: true,
|
|
34
|
-
document: freezeDocument(content, undefined, {}, sectionsRecord(spans, content), {
|
|
35
|
+
document: freezeDocument(content, undefined, {}, content.slice(0, spans[0]?.headingStart), sectionsRecord(spans, content), {
|
|
35
36
|
root: null,
|
|
36
37
|
yamlEnd: 0,
|
|
37
38
|
bodyStart: 0
|
|
@@ -56,7 +57,7 @@ export function parse(content, file = '') {
|
|
|
56
57
|
const record = fields;
|
|
57
58
|
return {
|
|
58
59
|
ok: true,
|
|
59
|
-
document: freezeDocument(content, declaredType(record), record, sectionsRecord(spans, content), {
|
|
60
|
+
document: freezeDocument(content, declaredType(record), record, content.slice(bodyStart, spans[0]?.headingStart), sectionsRecord(spans, content), {
|
|
60
61
|
root,
|
|
61
62
|
yamlEnd: fence.yamlEnd,
|
|
62
63
|
bodyStart
|
|
@@ -135,6 +136,22 @@ function applySection(document, name, value, prior) {
|
|
|
135
136
|
document: parsed.document
|
|
136
137
|
};
|
|
137
138
|
}
|
|
139
|
+
function applyPreamble(document, value, prior) {
|
|
140
|
+
if (document.preamble !== prior) return {
|
|
141
|
+
outcome: 'stale',
|
|
142
|
+
document
|
|
143
|
+
};
|
|
144
|
+
const start = bodyStartOf(document.content);
|
|
145
|
+
const parsed = parse(splice(document.content, start, start + document.preamble.length, value));
|
|
146
|
+
if (!parsed.ok) return {
|
|
147
|
+
outcome: 'refuse',
|
|
148
|
+
refusal: parsed.refusal
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
outcome: 'applied',
|
|
152
|
+
document: parsed.document
|
|
153
|
+
};
|
|
154
|
+
}
|
|
138
155
|
function fitsBare(to) {
|
|
139
156
|
if (to === '' || to.startsWith('<')) return false;
|
|
140
157
|
let depth = 0;
|
|
@@ -204,6 +221,7 @@ export function links(document, file) {
|
|
|
204
221
|
}
|
|
205
222
|
export function apply(document, change) {
|
|
206
223
|
if (change.kind === 'link') return applyLink(document, change.href, change.to);
|
|
224
|
+
if (change.kind === 'preamble') return applyPreamble(document, change.value, change.prior);
|
|
207
225
|
try {
|
|
208
226
|
if (change.kind === 'field') return applyField(document, change.name, change.value, change.prior);
|
|
209
227
|
return applySection(document, change.name, change.value, change.prior);
|
package/dist/document.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdmodel/src/document.ts"],"sourcesContent":["import { hrefOccurrences } from './links.js';\nimport { classifyHref, hrefSuffix } from './paths.js';\nimport { headingSpans, sectionsRecord } from './sections.js';\nimport { refusal } from './refuse.js';\nimport type { ApplyResult, Change, Document, Link, ParseResult } from './types.js';\nimport {\n bodyStartAfterYaml,\n bodyStartOf,\n equalValue,\n extractFrontmatter,\n jsValue,\n lineEnding,\n mapEntry,\n parseYamlMapping,\n serializeJs,\n serializeKey,\n YamlError,\n type YamlMap,\n} from './yaml.js';\n\ntype Internal = {\n readonly root: YamlMap | null;\n readonly yamlEnd: number;\n readonly bodyStart: number;\n};\n\nconst internals = new WeakMap<Document, Internal>();\n\nfunction refuse(file: string, rule: string, location?: string) {\n return location === undefined ? refusal(file, rule) : refusal(file, rule, { location });\n}\n\nfunction freezeDocument(\n content: string,\n type: string | undefined,\n fields: Record<string, unknown>,\n sections: Record<string, string>,\n internal: Internal,\n): Document {\n const document: Document = Object.freeze({\n content,\n type,\n fields: Object.freeze(fields),\n sections: Object.freeze(sections),\n });\n internals.set(document, internal);\n return document;\n}\n\nfunction declaredType(fields: Record<string, unknown>): string | undefined {\n const value = fields.type;\n if (value === undefined || value === null) return undefined;\n if (typeof value !== 'string' || value === '') return undefined;\n return value;\n}\n\nexport function parse(content: string, file = ''): ParseResult {\n const fence = extractFrontmatter(content);\n if (fence.kind === 'none') {\n const spans = headingSpans(content, 0);\n return {\n ok: true,\n document: freezeDocument(content, undefined, {}, sectionsRecord(spans, content), {\n root: null,\n yamlEnd: 0,\n bodyStart: 0,\n }),\n };\n }\n if (fence.kind === 'unclosed') return { ok: false, refusal: refuse(file, 'frontmatter-fence') };\n try {\n const root = parseYamlMapping(content, fence.yamlStart, fence.yamlEnd);\n const fields = jsValue(root);\n if (fields === null || typeof fields !== 'object' || Array.isArray(fields)) {\n return { ok: false, refusal: refuse(file, 'frontmatter-fence') };\n }\n const bodyStart = bodyStartAfterYaml(content, fence.yamlEnd);\n const spans = headingSpans(content, bodyStart);\n const record = fields as Record<string, unknown>;\n return {\n ok: true,\n document: freezeDocument(\n content,\n declaredType(record),\n record,\n sectionsRecord(spans, content),\n {\n root,\n yamlEnd: fence.yamlEnd,\n bodyStart,\n },\n ),\n };\n } catch (error) {\n if (error instanceof YamlError)\n return { ok: false, refusal: refuse(file, 'frontmatter-fence') };\n throw error;\n }\n}\n\nfunction splice(content: string, start: number, end: number, insert: string): string {\n return content.slice(0, start) + insert + content.slice(end);\n}\n\nfunction applyField(document: Document, name: string, value: unknown, prior: unknown): ApplyResult {\n const internal = internals.get(document);\n if (internal === undefined || internal.root === null) {\n return { outcome: 'refuse', refusal: refuse('', 'frontmatter-fence', name) };\n }\n if (!equalValue(document.fields[name], prior)) {\n return { outcome: 'stale', document };\n }\n let nextContent: string;\n const existing = mapEntry(internal.root, name);\n if (existing !== undefined) {\n nextContent = splice(\n document.content,\n existing.value.start,\n existing.value.end,\n serializeJs(value),\n );\n } else {\n const nl = lineEnding(document.content);\n const line = `${serializeKey(name)}: ${serializeJs(value)}${nl}`;\n const before = document.content.slice(0, internal.yamlEnd);\n const prefix = before.endsWith('\\n') || before.endsWith('\\r\\n') ? '' : nl;\n nextContent = splice(document.content, internal.yamlEnd, internal.yamlEnd, `${prefix}${line}`);\n }\n const parsed = parse(nextContent);\n if (!parsed.ok) return { outcome: 'refuse', refusal: parsed.refusal };\n return { outcome: 'applied', document: parsed.document };\n}\n\nfunction applySection(document: Document, name: string, value: string, prior: string): ApplyResult {\n const internal = internals.get(document);\n if (internal === undefined)\n return { outcome: 'refuse', refusal: refuse('', 'required-section', name) };\n const spans = headingSpans(document.content, internal.bodyStart);\n const span = spans.find((item) => item.name === name);\n if (span === undefined)\n return { outcome: 'refuse', refusal: refuse('', 'required-section', name) };\n const current = document.content.slice(span.bodyStart, span.bodyEnd);\n if (current !== prior) return { outcome: 'stale', document };\n const parsed = parse(splice(document.content, span.bodyStart, span.bodyEnd, value));\n if (!parsed.ok) return { outcome: 'refuse', refusal: parsed.refusal };\n return { outcome: 'applied', document: parsed.document };\n}\n\nfunction fitsBare(to: string): boolean {\n if (to === '' || to.startsWith('<')) return false;\n let depth = 0;\n for (const character of to) {\n if (/[\\s\\u0000-\\u001f\\u007f]/.test(character)) return false;\n if (character === '(') depth += 1;\n else if (character === ')') {\n if (depth === 0) return false;\n depth -= 1;\n }\n }\n return depth === 0;\n}\n\nfunction fitsBrackets(to: string): boolean {\n return to !== '' && !/[<>\\n\\r]/.test(to);\n}\n\nfunction destinationText(to: string, bracketed: boolean): string | null {\n if (fitsBare(to)) return bracketed && fitsBrackets(to) ? `<${to}>` : to;\n if (fitsBrackets(to)) return `<${to}>`;\n return null;\n}\n\nfunction applyLink(document: Document, href: string, to: string): ApplyResult {\n const content = document.content;\n const bodyStart = bodyStartOf(content);\n const matches = hrefOccurrences(content.slice(bodyStart)).filter(\n (occurrence) => occurrence.href === href,\n );\n if (matches.length === 0) return { outcome: 'stale', document };\n const written = to + hrefSuffix(href);\n let rewritten = '';\n let cursor = 0;\n for (const match of matches) {\n const text = destinationText(written, match.bracketed);\n if (text === null)\n return { outcome: 'refuse', refusal: refuse('', 'unwritable-link', written) };\n rewritten += content.slice(cursor, bodyStart + match.start);\n rewritten += text;\n cursor = bodyStart + match.end;\n }\n const parsed = parse(rewritten + content.slice(cursor));\n if (!parsed.ok) return { outcome: 'refuse', refusal: parsed.refusal };\n return { outcome: 'applied', document: parsed.document };\n}\n\nexport function links(document: Document, file: string): readonly Link[] {\n const found: Link[] = [];\n const seen = new Set<string>();\n for (const occurrence of hrefOccurrences(document.content.slice(bodyStartOf(document.content)))) {\n if (seen.has(occurrence.href)) continue;\n const resolved = classifyHref(file, occurrence.href);\n if (resolved.kind !== 'path') continue;\n seen.add(occurrence.href);\n found.push({ href: occurrence.href, target: resolved.path });\n }\n return found;\n}\n\nexport function apply(document: Document, change: Change): ApplyResult {\n if (change.kind === 'link') return applyLink(document, change.href, change.to);\n try {\n if (change.kind === 'field')\n return applyField(document, change.name, change.value, change.prior);\n return applySection(document, change.name, change.value, change.prior);\n } catch (error) {\n if (error instanceof YamlError) {\n return { outcome: 'refuse', refusal: refuse('', 'frontmatter-fence', change.name) };\n }\n throw error;\n }\n}\n\nexport function serialize(document: Document): string {\n return document.content;\n}\n"],"names":["hrefOccurrences","classifyHref","hrefSuffix","headingSpans","sectionsRecord","refusal","bodyStartAfterYaml","bodyStartOf","equalValue","extractFrontmatter","jsValue","lineEnding","mapEntry","parseYamlMapping","serializeJs","serializeKey","YamlError","internals","WeakMap","refuse","file","rule","location","undefined","freezeDocument","content","type","fields","sections","internal","document","Object","freeze","set","declaredType","value","parse","fence","kind","spans","ok","root","yamlEnd","bodyStart","yamlStart","Array","isArray","record","error","splice","start","end","insert","slice","applyField","name","prior","get","outcome","nextContent","existing","nl","line","before","prefix","endsWith","parsed","applySection","span","find","item","current","bodyEnd","fitsBare","to","startsWith","depth","character","test","fitsBrackets","destinationText","bracketed","applyLink","href","matches","filter","occurrence","length","written","rewritten","cursor","match","text","links","found","seen","Set","has","resolved","add","push","target","path","apply","change","serialize"],"mappings":"AAAA,SAASA,eAAe,QAAQ,aAAa;AAC7C,SAASC,YAAY,EAAEC,UAAU,QAAQ,aAAa;AACtD,SAASC,YAAY,EAAEC,cAAc,QAAQ,gBAAgB;AAC7D,SAASC,OAAO,QAAQ,cAAc;AAEtC,SACEC,kBAAkB,EAClBC,WAAW,EACXC,UAAU,EACVC,kBAAkB,EAClBC,OAAO,EACPC,UAAU,EACVC,QAAQ,EACRC,gBAAgB,EAChBC,WAAW,EACXC,YAAY,EACZC,SAAS,QAEJ,YAAY;AAQnB,MAAMC,YAAY,IAAIC;AAEtB,SAASC,OAAOC,IAAY,EAAEC,IAAY,EAAEC,QAAiB;IAC3D,OAAOA,aAAaC,YAAYlB,QAAQe,MAAMC,QAAQhB,QAAQe,MAAMC,MAAM;QAAEC;IAAS;AACvF;AAEA,SAASE,eACPC,OAAe,EACfC,IAAwB,EACxBC,MAA+B,EAC/BC,QAAgC,EAChCC,QAAkB;IAElB,MAAMC,WAAqBC,OAAOC,MAAM,CAAC;QACvCP;QACAC;QACAC,QAAQI,OAAOC,MAAM,CAACL;QACtBC,UAAUG,OAAOC,MAAM,CAACJ;IAC1B;IACAX,UAAUgB,GAAG,CAACH,UAAUD;IACxB,OAAOC;AACT;AAEA,SAASI,aAAaP,MAA+B;IACnD,MAAMQ,QAAQR,OAAOD,IAAI;IACzB,IAAIS,UAAUZ,aAAaY,UAAU,MAAM,OAA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ACxB,MAAMC,OAAO,IAAIC;IACjB,KAAK,MAAMV,cAActF,gBAAgB8B,SAASL,OAAO,CAAC4B,KAAK,CAAC9C,YAAYuB,SAASL,OAAO,IAAK;QAC/F,IAAIsE,KAAKE,GAAG,CAACX,WAAWH,IAAI,GAAG;QAC/B,MAAMe,WAAWjG,aAAamB,MAAMkE,WAAWH,IAAI;QACnD,IAAIe,SAAS5D,IAAI,KAAK,QAAQ;QAC9ByD,KAAKI,GAAG,CAACb,WAAWH,IAAI;QACxBW,MAAMM,IAAI,CAAC;YAAEjB,MAAMG,WAAWH,IAAI;YAAEkB,QAAQH,SAASI,IAAI;QAAC;IAC5D;IACA,OAAOR;AACT;AAEA,OAAO,SAASS,MAAMzE,QAAkB,EAAE0E,MAAc;IACtD,IAAIA,OAAOlE,IAAI,KAAK,QAAQ,OAAO4C,UAAUpD,UAAU0E,OAAOrB,IAAI,EAAEqB,OAAO9B,EAAE;IAC7E,IAAI;QACF,IAAI8B,OAAOlE,IAAI,KAAK,SAClB,OAAOgB,WAAWxB,UAAU0E,OAAOjD,IAAI,EAAEiD,OAAOrE,KAAK,EAAEqE,OAAOhD,KAAK;QACrE,OAAOW,aAAarC,UAAU0E,OAAOjD,IAAI,EAAEiD,OAAOrE,KAAK,EAAEqE,OAAOhD,KAAK;IACvE,EAAE,OAAOR,OAAO;QACd,IAAIA,iBAAiBhC,WAAW;YAC9B,OAAO;gBAAE0C,SAAS;gBAAUrD,SAASc,OAAO,IAAI,qBAAqBqF,OAAOjD,IAAI;YAAE;QACpF;QACA,MAAMP;IACR;AACF;AAEA,OAAO,SAASyD,UAAU3E,QAAkB;IAC1C,OAAOA,SAASL,OAAO;AACzB"}
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdmodel/src/document.ts"],"sourcesContent":["import { hrefOccurrences } from './links.js';\nimport { classifyHref, hrefSuffix } from './paths.js';\nimport { headingSpans, sectionsRecord } from './sections.js';\nimport { refusal } from './refuse.js';\nimport type { ApplyResult, Change, Document, Link, ParseResult } from './types.js';\nimport {\n bodyStartAfterYaml,\n bodyStartOf,\n equalValue,\n extractFrontmatter,\n jsValue,\n lineEnding,\n mapEntry,\n parseYamlMapping,\n serializeJs,\n serializeKey,\n YamlError,\n type YamlMap,\n} from './yaml.js';\n\ntype Internal = {\n readonly root: YamlMap | null;\n readonly yamlEnd: number;\n readonly bodyStart: number;\n};\n\nconst internals = new WeakMap<Document, Internal>();\n\nfunction refuse(file: string, rule: string, location?: string) {\n return location === undefined ? refusal(file, rule) : refusal(file, rule, { location });\n}\n\nfunction freezeDocument(\n content: string,\n type: string | undefined,\n fields: Record<string, unknown>,\n preamble: string,\n sections: Record<string, string>,\n internal: Internal,\n): Document {\n const document: Document = Object.freeze({\n content,\n type,\n fields: Object.freeze(fields),\n preamble,\n sections: Object.freeze(sections),\n });\n internals.set(document, internal);\n return document;\n}\n\nfunction declaredType(fields: Record<string, unknown>): string | undefined {\n const value = fields.type;\n if (value === undefined || value === null) return undefined;\n if (typeof value !== 'string' || value === '') return undefined;\n return value;\n}\n\nexport function parse(content: string, file = ''): ParseResult {\n const fence = extractFrontmatter(content);\n if (fence.kind === 'none') {\n const spans = headingSpans(content, 0);\n return {\n ok: true,\n document: freezeDocument(\n content,\n undefined,\n {},\n content.slice(0, spans[0]?.headingStart),\n sectionsRecord(spans, content),\n {\n root: null,\n yamlEnd: 0,\n bodyStart: 0,\n },\n ),\n };\n }\n if (fence.kind === 'unclosed') return { ok: false, refusal: refuse(file, 'frontmatter-fence') };\n try {\n const root = parseYamlMapping(content, fence.yamlStart, fence.yamlEnd);\n const fields = jsValue(root);\n if (fields === null || typeof fields !== 'object' || Array.isArray(fields)) {\n return { ok: false, refusal: refuse(file, 'frontmatter-fence') };\n }\n const bodyStart = bodyStartAfterYaml(content, fence.yamlEnd);\n const spans = headingSpans(content, bodyStart);\n const record = fields as Record<string, unknown>;\n return {\n ok: true,\n document: freezeDocument(\n content,\n declaredType(record),\n record,\n content.slice(bodyStart, spans[0]?.headingStart),\n sectionsRecord(spans, content),\n {\n root,\n yamlEnd: fence.yamlEnd,\n bodyStart,\n },\n ),\n };\n } catch (error) {\n if (error instanceof YamlError)\n return { ok: false, refusal: refuse(file, 'frontmatter-fence') };\n throw error;\n }\n}\n\nfunction splice(content: string, start: number, end: number, insert: string): string {\n return content.slice(0, start) + insert + content.slice(end);\n}\n\nfunction applyField(document: Document, name: string, value: unknown, prior: unknown): ApplyResult {\n const internal = internals.get(document);\n if (internal === undefined || internal.root === null) {\n return { outcome: 'refuse', refusal: refuse('', 'frontmatter-fence', name) };\n }\n if (!equalValue(document.fields[name], prior)) {\n return { outcome: 'stale', document };\n }\n let nextContent: string;\n const existing = mapEntry(internal.root, name);\n if (existing !== undefined) {\n nextContent = splice(\n document.content,\n existing.value.start,\n existing.value.end,\n serializeJs(value),\n );\n } else {\n const nl = lineEnding(document.content);\n const line = `${serializeKey(name)}: ${serializeJs(value)}${nl}`;\n const before = document.content.slice(0, internal.yamlEnd);\n const prefix = before.endsWith('\\n') || before.endsWith('\\r\\n') ? '' : nl;\n nextContent = splice(document.content, internal.yamlEnd, internal.yamlEnd, `${prefix}${line}`);\n }\n const parsed = parse(nextContent);\n if (!parsed.ok) return { outcome: 'refuse', refusal: parsed.refusal };\n return { outcome: 'applied', document: parsed.document };\n}\n\nfunction applySection(document: Document, name: string, value: string, prior: string): ApplyResult {\n const internal = internals.get(document);\n if (internal === undefined)\n return { outcome: 'refuse', refusal: refuse('', 'required-section', name) };\n const spans = headingSpans(document.content, internal.bodyStart);\n const span = spans.find((item) => item.name === name);\n if (span === undefined)\n return { outcome: 'refuse', refusal: refuse('', 'required-section', name) };\n const current = document.content.slice(span.bodyStart, span.bodyEnd);\n if (current !== prior) return { outcome: 'stale', document };\n const parsed = parse(splice(document.content, span.bodyStart, span.bodyEnd, value));\n if (!parsed.ok) return { outcome: 'refuse', refusal: parsed.refusal };\n return { outcome: 'applied', document: parsed.document };\n}\n\nfunction applyPreamble(document: Document, value: string, prior: string): ApplyResult {\n if (document.preamble !== prior) return { outcome: 'stale', document };\n const start = bodyStartOf(document.content);\n const parsed = parse(splice(document.content, start, start + document.preamble.length, value));\n if (!parsed.ok) return { outcome: 'refuse', refusal: parsed.refusal };\n return { outcome: 'applied', document: parsed.document };\n}\n\nfunction fitsBare(to: string): boolean {\n if (to === '' || to.startsWith('<')) return false;\n let depth = 0;\n for (const character of to) {\n if (/[\\s\\u0000-\\u001f\\u007f]/.test(character)) return false;\n if (character === '(') depth += 1;\n else if (character === ')') {\n if (depth === 0) return false;\n depth -= 1;\n }\n }\n return depth === 0;\n}\n\nfunction fitsBrackets(to: string): boolean {\n return to !== '' && !/[<>\\n\\r]/.test(to);\n}\n\nfunction destinationText(to: string, bracketed: boolean): string | null {\n if (fitsBare(to)) return bracketed && fitsBrackets(to) ? `<${to}>` : to;\n if (fitsBrackets(to)) return `<${to}>`;\n return null;\n}\n\nfunction applyLink(document: Document, href: string, to: string): ApplyResult {\n const content = document.content;\n const bodyStart = bodyStartOf(content);\n const matches = hrefOccurrences(content.slice(bodyStart)).filter(\n (occurrence) => occurrence.href === href,\n );\n if (matches.length === 0) return { outcome: 'stale', document };\n const written = to + hrefSuffix(href);\n let rewritten = '';\n let cursor = 0;\n for (const match of matches) {\n const text = destinationText(written, match.bracketed);\n if (text === null)\n return { outcome: 'refuse', refusal: refuse('', 'unwritable-link', written) };\n rewritten += content.slice(cursor, bodyStart + match.start);\n rewritten += text;\n cursor = bodyStart + match.end;\n }\n const parsed = parse(rewritten + content.slice(cursor));\n if (!parsed.ok) return { outcome: 'refuse', refusal: parsed.refusal };\n return { outcome: 'applied', document: parsed.document };\n}\n\nexport function links(document: Document, file: string): readonly Link[] {\n const found: Link[] = [];\n const seen = new Set<string>();\n for (const occurrence of hrefOccurrences(document.content.slice(bodyStartOf(document.content)))) {\n if (seen.has(occurrence.href)) continue;\n const resolved = classifyHref(file, occurrence.href);\n if (resolved.kind !== 'path') continue;\n seen.add(occurrence.href);\n found.push({ href: occurrence.href, target: resolved.path });\n }\n return found;\n}\n\nexport function apply(document: Document, change: Change): ApplyResult {\n if (change.kind === 'link') return applyLink(document, change.href, change.to);\n if (change.kind === 'preamble') return applyPreamble(document, change.value, change.prior);\n try {\n if (change.kind === 'field')\n return applyField(document, change.name, change.value, change.prior);\n return applySection(document, change.name, change.value, change.prior);\n } catch (error) {\n if (error instanceof YamlError) {\n return { outcome: 'refuse', refusal: refuse('', 'frontmatter-fence', change.name) };\n }\n throw error;\n }\n}\n\nexport function serialize(document: Document): string {\n return document.content;\n}\n"],"names":["hrefOccurrences","classifyHref","hrefSuffix","headingSpans","sectionsRecord","refusal","bodyStartAfterYaml","bodyStartOf","equalValue","extractFrontmatter","jsValue","lineEnding","mapEntry","parseYamlMapping","serializeJs","serializeKey","YamlError","internals","WeakMap","refuse","file","rule","location","undefined","freezeDocument","content","type","fields","preamble","sections","internal","document","Object","freeze","set","declaredType","value","parse","fence","kind","spans","ok","slice","headingStart","root","yamlEnd","bodyStart","yamlStart","Array","isArray","record","error","splice","start","end","insert","applyField","name","prior","get","outcome","nextContent","existing","nl","line","before","prefix","endsWith","parsed","applySection","span","find","item","current","bodyEnd","applyPreamble","length","fitsBare","to","startsWith","depth","character","test","fitsBrackets","destinationText","bracketed","applyLink","href","matches","filter","occurrence","written","rewritten","cursor","match","text","links","found","seen","Set","has","resolved","add","push","target","path","apply","change","serialize"],"mappings":"AAAA,SAASA,eAAe,QAAQ,aAAa;AAC7C,SAASC,YAAY,EAAEC,UAAU,QAAQ,aAAa;AACtD,SAASC,YAAY,EAAEC,cAAc,QAAQ,gBAAgB;AAC7D,SAASC,OAAO,QAAQ,cAAc;AAEtC,SACEC,kBAAkB,EAClBC,WAAW,EACXC,UAAU,EACVC,kBAAkB,EAClBC,OAAO,EACPC,UAAU,EACVC,QAAQ,EACRC,gBAAgB,EAChBC,WAAW,EACXC,YAAY,EACZC,SAAS,QAEJ,YAAY;AAQnB,MAAMC,YAAY,IAAIC;AAEtB,SAASC,OAAOC,IA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CAACV,WAAWH,IAAI,GAAG;QAC/B,MAAMc,WAAWpG,aAAamB,MAAMsE,WAAWH,IAAI;QACnD,IAAIc,SAAS9D,IAAI,KAAK,QAAQ;QAC9B2D,KAAKI,GAAG,CAACZ,WAAWH,IAAI;QACxBU,MAAMM,IAAI,CAAC;YAAEhB,MAAMG,WAAWH,IAAI;YAAEiB,QAAQH,SAASI,IAAI;QAAC;IAC5D;IACA,OAAOR;AACT;AAEA,OAAO,SAASS,MAAM3E,QAAkB,EAAE4E,MAAc;IACtD,IAAIA,OAAOpE,IAAI,KAAK,QAAQ,OAAO+C,UAAUvD,UAAU4E,OAAOpB,IAAI,EAAEoB,OAAO7B,EAAE;IAC7E,IAAI6B,OAAOpE,IAAI,KAAK,YAAY,OAAOoC,cAAc5C,UAAU4E,OAAOvE,KAAK,EAAEuE,OAAOjD,KAAK;IACzF,IAAI;QACF,IAAIiD,OAAOpE,IAAI,KAAK,SAClB,OAAOiB,WAAWzB,UAAU4E,OAAOlD,IAAI,EAAEkD,OAAOvE,KAAK,EAAEuE,OAAOjD,KAAK;QACrE,OAAOW,aAAatC,UAAU4E,OAAOlD,IAAI,EAAEkD,OAAOvE,KAAK,EAAEuE,OAAOjD,KAAK;IACvE,EAAE,OAAOP,OAAO;QACd,IAAIA,iBAAiBnC,WAAW;YAC9B,OAAO;gBAAE4C,SAAS;gBAAUvD,SAASc,OAAO,IAAI,qBAAqBwF,OAAOlD,IAAI;YAAE;QACpF;QACA,MAAMN;IACR;AACF;AAEA,OAAO,SAASyD,UAAU7E,QAAkB;IAC1C,OAAOA,SAASN,OAAO;AACzB"}
|
package/dist/types.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export type Document = {
|
|
|
6
6
|
readonly content: string;
|
|
7
7
|
readonly type: string | undefined;
|
|
8
8
|
readonly fields: Readonly<Record<string, unknown>>;
|
|
9
|
+
readonly preamble: string;
|
|
9
10
|
readonly sections: Readonly<Record<string, string>>;
|
|
10
11
|
};
|
|
11
12
|
export type Refusal = {
|
|
@@ -41,6 +42,10 @@ export type Change = {
|
|
|
41
42
|
readonly name: string;
|
|
42
43
|
readonly value: string;
|
|
43
44
|
readonly prior: string;
|
|
45
|
+
} | {
|
|
46
|
+
readonly kind: 'preamble';
|
|
47
|
+
readonly value: string;
|
|
48
|
+
readonly prior: string;
|
|
44
49
|
} | {
|
|
45
50
|
readonly kind: 'link';
|
|
46
51
|
readonly href: string;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEvD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACrD,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,C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,QAAQ,CAAA;CAAE,GAC1D;IAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdmodel/src/types.ts"],"sourcesContent":["export type Library = Readonly<Record<string, string>>;\n\nexport type ValidationContext = {\n readonly binaryTargets: readonly string[];\n};\n\nexport type Document = {\n readonly content: string;\n readonly type: string | undefined;\n readonly fields: Readonly<Record<string, unknown>>;\n readonly sections: Readonly<Record<string, string>>;\n};\n\nexport type Refusal = {\n readonly file: string;\n readonly rule: string;\n readonly version: string;\n readonly location?: string;\n readonly referrers?: readonly string[];\n};\n\nexport type Validation =\n | { readonly verdict: 'accept' }\n | ({ readonly verdict: 'refuse' } & Refusal);\n\nexport type ParseResult =\n | { readonly ok: true; readonly document: Document }\n | { readonly ok: false; readonly refusal: Refusal };\n\nexport type Link = {\n readonly href: string;\n readonly target: string;\n};\n\nexport type Change =\n | {\n readonly kind: 'field';\n readonly name: string;\n readonly value: unknown;\n readonly prior: unknown;\n }\n | {\n readonly kind: 'section';\n readonly name: string;\n readonly value: string;\n readonly prior: string;\n }\n | {\n readonly kind: 'link';\n readonly href: string;\n readonly to: string;\n };\n\nexport type ApplyResult =\n | { readonly outcome: 'applied'; readonly document: Document }\n | { readonly outcome: 'stale'; readonly document: Document }\n | { readonly outcome: 'refuse'; readonly refusal: Refusal };\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdmodel/src/types.ts"],"sourcesContent":["export type Library = Readonly<Record<string, string>>;\n\nexport type ValidationContext = {\n readonly binaryTargets: readonly string[];\n};\n\nexport type Document = {\n readonly content: string;\n readonly type: string | undefined;\n readonly fields: Readonly<Record<string, unknown>>;\n readonly preamble: string;\n readonly sections: Readonly<Record<string, string>>;\n};\n\nexport type Refusal = {\n readonly file: string;\n readonly rule: string;\n readonly version: string;\n readonly location?: string;\n readonly referrers?: readonly string[];\n};\n\nexport type Validation =\n | { readonly verdict: 'accept' }\n | ({ readonly verdict: 'refuse' } & Refusal);\n\nexport type ParseResult =\n | { readonly ok: true; readonly document: Document }\n | { readonly ok: false; readonly refusal: Refusal };\n\nexport type Link = {\n readonly href: string;\n readonly target: string;\n};\n\nexport type Change =\n | {\n readonly kind: 'field';\n readonly name: string;\n readonly value: unknown;\n readonly prior: unknown;\n }\n | {\n readonly kind: 'section';\n readonly name: string;\n readonly value: string;\n readonly prior: string;\n }\n | {\n readonly kind: 'preamble';\n readonly value: string;\n readonly prior: string;\n }\n | {\n readonly kind: 'link';\n readonly href: string;\n readonly to: string;\n };\n\nexport type ApplyResult =\n | { readonly outcome: 'applied'; readonly document: Document }\n | { readonly outcome: 'stale'; readonly document: Document }\n | { readonly outcome: 'refuse'; readonly refusal: Refusal };\n"],"names":[],"mappings":"AA2DA,WAG8D"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.0-alpha.
|
|
1
|
+
export declare const VERSION = "0.1.0-alpha.5";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
package/dist/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdmodel/src/version.ts"],"sourcesContent":["export const VERSION = '0.1.0-alpha.
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdmodel/src/version.ts"],"sourcesContent":["export const VERSION = '0.1.0-alpha.5';\n"],"names":["VERSION"],"mappings":"AAAA,OAAO,MAAMA,UAAU,gBAAgB"}
|
package/fixtures/README.md
CHANGED
|
@@ -7,6 +7,20 @@ compare `validate(library, context)` against `expected.json`. Text-only cases
|
|
|
7
7
|
carry `{ "binaryTargets": [] }`. Binary targets are membership declarations;
|
|
8
8
|
the corpus supplies no binary bytes or placeholder Documents.
|
|
9
9
|
|
|
10
|
+
## Preamble operations
|
|
11
|
+
|
|
12
|
+
`preamble.json` exercises the public parse/apply/serialize seam separately from
|
|
13
|
+
the validation Libraries. Each row carries `name`, exact `source`, expected
|
|
14
|
+
`preamble`, replacement `value`, and exact serialized `expected` output. Parse
|
|
15
|
+
the source, compare `Document.preamble`, apply
|
|
16
|
+
`{ kind: 'preamble', prior: preamble, value }`, and compare the serialized result.
|
|
17
|
+
These cases cover empty and heading-free Documents, frontmatter boundaries,
|
|
18
|
+
fenced headings, newline/source preservation, and the Runtime moved-export
|
|
19
|
+
example from its [approved candidate](https://github.com/agentshouse/mdruntime/blob/ed0a6f0b95317d9ade846ec1f2871a3997519bc4/test/rooms.ts).
|
|
20
|
+
The package check runs every row in ESM, CommonJS, and the browser-target VM
|
|
21
|
+
bundle, also checking stale priors, immutable Documents, and conversion of the
|
|
22
|
+
Runtime link rewrite into a preamble operation through public APIs.
|
|
23
|
+
|
|
10
24
|
## Verdict format
|
|
11
25
|
|
|
12
26
|
Acceptance:
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"name": "CRLF frontmatter and H2 closing syntax",
|
|
4
|
+
"source": "---\r\ntype: note\r\ntitle: \"Kept\" # syntax\r\n---\r\n\r\n# Title\r\nIntro.\r\n\r\n## Body ###\r\nKept.\r\n",
|
|
5
|
+
"preamble": "\r\n# Title\r\nIntro.\r\n\r\n",
|
|
6
|
+
"value": "\r\nNew intro.\r\n\r\n",
|
|
7
|
+
"expected": "---\r\ntype: note\r\ntitle: \"Kept\" # syntax\r\n---\r\n\r\nNew intro.\r\n\r\n## Body ###\r\nKept.\r\n"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"name": "untyped document without sections",
|
|
11
|
+
"source": "# Title\nAll body text.",
|
|
12
|
+
"preamble": "# Title\nAll body text.",
|
|
13
|
+
"value": "Replaced without final newline.",
|
|
14
|
+
"expected": "Replaced without final newline."
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"name": "typed document without sections",
|
|
18
|
+
"source": "---\ntype: note\n---\n# Title\nAll body text.",
|
|
19
|
+
"preamble": "# Title\nAll body text.",
|
|
20
|
+
"value": "New body.\n",
|
|
21
|
+
"expected": "---\ntype: note\n---\nNew body.\n"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"name": "empty document",
|
|
25
|
+
"source": "",
|
|
26
|
+
"preamble": "",
|
|
27
|
+
"value": "First text.\n",
|
|
28
|
+
"expected": "First text.\n"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "frontmatter only",
|
|
32
|
+
"source": "---\ntype: note\n---\n",
|
|
33
|
+
"preamble": "",
|
|
34
|
+
"value": "First text.\n",
|
|
35
|
+
"expected": "---\ntype: note\n---\nFirst text.\n"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"name": "frontmatter delimiter at EOF",
|
|
39
|
+
"source": "---\ntype: note\n---",
|
|
40
|
+
"preamble": "",
|
|
41
|
+
"value": "\nFirst text.",
|
|
42
|
+
"expected": "---\ntype: note\n---\nFirst text."
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"name": "section starts at offset zero",
|
|
46
|
+
"source": "## Body\nKept.\n",
|
|
47
|
+
"preamble": "",
|
|
48
|
+
"value": "Intro.\n\n",
|
|
49
|
+
"expected": "Intro.\n\n## Body\nKept.\n"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"name": "section immediately after frontmatter",
|
|
53
|
+
"source": "---\ntype: note\n---\n## Body\nKept.\n",
|
|
54
|
+
"preamble": "",
|
|
55
|
+
"value": "Intro.\n",
|
|
56
|
+
"expected": "---\ntype: note\n---\nIntro.\n## Body\nKept.\n"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"name": "backtick fence hides a heading",
|
|
60
|
+
"source": "```md\n## Example\n```\n\n## Body\nKept.\n",
|
|
61
|
+
"preamble": "```md\n## Example\n```\n\n",
|
|
62
|
+
"value": "Example removed.\n",
|
|
63
|
+
"expected": "Example removed.\n## Body\nKept.\n"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"name": "tilde fence hides a heading",
|
|
67
|
+
"source": " ~~~md\n## Example\n ~~~\n\n## Body\nKept.",
|
|
68
|
+
"preamble": " ~~~md\n## Example\n ~~~\n\n",
|
|
69
|
+
"value": "Example removed.\n",
|
|
70
|
+
"expected": "Example removed.\n## Body\nKept."
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"name": "unclosed fence carries the entire body",
|
|
74
|
+
"source": "---\ntype: note\n---\n```\n## Example\n",
|
|
75
|
+
"preamble": "```\n## Example\n",
|
|
76
|
+
"value": "Plain replacement.\n",
|
|
77
|
+
"expected": "---\ntype: note\n---\nPlain replacement.\n"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"name": "existing section parser ignores other heading forms",
|
|
81
|
+
"source": "# Title\n### Subheading\n> ## Quoted\n ## Indented\nSetext\n------\n\n## Actual ##\nKept.\n",
|
|
82
|
+
"preamble": "# Title\n### Subheading\n> ## Quoted\n ## Indented\nSetext\n------\n\n",
|
|
83
|
+
"value": "Intro.\n",
|
|
84
|
+
"expected": "Intro.\n## Actual ##\nKept.\n"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"name": "Unicode and mixed newlines",
|
|
88
|
+
"source": "---\r\ntype: note\r\n---\r\n🙂 Вступ\r\n\n## Body\nKept.\r\n",
|
|
89
|
+
"preamble": "🙂 Вступ\r\n\n",
|
|
90
|
+
"value": "Новий 🙂\n\n",
|
|
91
|
+
"expected": "---\r\ntype: note\r\n---\r\nНовий 🙂\n\n## Body\nKept.\r\n"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"name": "heading at EOF and empty replacement",
|
|
95
|
+
"source": "Intro.\n\n## Body",
|
|
96
|
+
"preamble": "Intro.\n\n",
|
|
97
|
+
"value": "",
|
|
98
|
+
"expected": "## Body"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"name": "Runtime moved export link",
|
|
102
|
+
"source": "---\ntype: note\ntitle: Filed note\n---\n\nFiled beside [the export](../data/export.csv).\n\n## Body\n\nThe destination above sits outside every section.\n",
|
|
103
|
+
"preamble": "\nFiled beside [the export](../data/export.csv).\n\n",
|
|
104
|
+
"value": "\nFiled beside [the export](../files/export.csv).\n\n",
|
|
105
|
+
"expected": "---\ntype: note\ntitle: Filed note\n---\n\nFiled beside [the export](../files/export.csv).\n\n## Body\n\nThe destination above sits outside every section.\n"
|
|
106
|
+
}
|
|
107
|
+
]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/mdmodel",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.5",
|
|
4
4
|
"description": "MD Type language, parser, validator, structured change application, Markdown syntax profile, and conformance fixtures",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|