@refrakt-md/runes 0.35.0 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/file-ref-resolve.d.ts.map +1 -1
- package/dist/file-ref-resolve.js +36 -1
- package/dist/file-ref-resolve.js.map +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/lang-map.d.ts.map +1 -1
- package/dist/lang-map.js +8 -0
- package/dist/lang-map.js.map +1 -1
- package/dist/lib/anchor.d.ts +73 -0
- package/dist/lib/anchor.d.ts.map +1 -0
- package/dist/lib/anchor.js +521 -0
- package/dist/lib/anchor.js.map +1 -0
- package/dist/lib/component.d.ts +1 -1
- package/dist/lib/component.d.ts.map +1 -1
- package/dist/lib/invocation.d.ts +22 -0
- package/dist/lib/invocation.d.ts.map +1 -0
- package/dist/lib/invocation.js +67 -0
- package/dist/lib/invocation.js.map +1 -0
- package/dist/lib/languages.d.ts +163 -0
- package/dist/lib/languages.d.ts.map +1 -0
- package/dist/lib/languages.js +383 -0
- package/dist/lib/languages.js.map +1 -0
- package/dist/lib/line-diff.d.ts +35 -0
- package/dist/lib/line-diff.d.ts.map +1 -0
- package/dist/lib/line-diff.js +77 -0
- package/dist/lib/line-diff.js.map +1 -0
- package/dist/lib/mask.d.ts +116 -0
- package/dist/lib/mask.d.ts.map +1 -0
- package/dist/lib/mask.js +378 -0
- package/dist/lib/mask.js.map +1 -0
- package/dist/lib/node.d.ts +1 -1
- package/dist/lib/node.d.ts.map +1 -1
- package/dist/lib/present.d.ts +73 -0
- package/dist/lib/present.d.ts.map +1 -0
- package/dist/lib/present.js +127 -0
- package/dist/lib/present.js.map +1 -0
- package/dist/lib/read-file.d.ts +21 -1
- package/dist/lib/read-file.d.ts.map +1 -1
- package/dist/lib/read-file.js +46 -0
- package/dist/lib/read-file.js.map +1 -1
- package/dist/lib/renderable.d.ts +7 -3
- package/dist/lib/renderable.d.ts.map +1 -1
- package/dist/lib/renderable.js +2 -2
- package/dist/lib/renderable.js.map +1 -1
- package/dist/lib/review-marker.d.ts +113 -0
- package/dist/lib/review-marker.d.ts.map +1 -0
- package/dist/lib/review-marker.js +173 -0
- package/dist/lib/review-marker.js.map +1 -0
- package/dist/snippet-pipeline.d.ts.map +1 -1
- package/dist/snippet-pipeline.js +70 -2
- package/dist/snippet-pipeline.js.map +1 -1
- package/dist/tags/diff.d.ts.map +1 -1
- package/dist/tags/diff.js +1 -38
- package/dist/tags/diff.js.map +1 -1
- package/dist/tags/file-ref.d.ts.map +1 -1
- package/dist/tags/file-ref.js +59 -1
- package/dist/tags/file-ref.js.map +1 -1
- package/dist/tags/snippet.d.ts.map +1 -1
- package/dist/tags/snippet.js +53 -2
- package/dist/tags/snippet.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anchor resolution and extents (SPEC-131 steps 2–8; WORK-587, WORK-588).
|
|
3
|
+
*
|
|
4
|
+
* Addresses a region of a file by **name** rather than by coordinate. A line
|
|
5
|
+
* range is a coordinate into a file nobody promised to hold still; an anchor
|
|
6
|
+
* that stops matching fails loudly instead of rendering a plausible wrong span.
|
|
7
|
+
*
|
|
8
|
+
* Two independent halves. Finding the anchor is a regex problem and is easy.
|
|
9
|
+
* Finding the extent is not a regex problem — but it is not a grammar problem
|
|
10
|
+
* either, which is what makes ~200 table-driven lines beat a parser that would
|
|
11
|
+
* work on TypeScript and be useless on the CSS, Markdown, JSON and shell the
|
|
12
|
+
* docs also quote (D1).
|
|
13
|
+
*
|
|
14
|
+
* **Anchors match raw source; the mask only rejects.** Matching against masked
|
|
15
|
+
* text blanks every string literal, so `match='"scripts"'` against
|
|
16
|
+
* `package.json` could never match. The mask is still needed in the other
|
|
17
|
+
* direction: an anchor landing *inside* a comment or a string is a false
|
|
18
|
+
* positive and is skipped.
|
|
19
|
+
*
|
|
20
|
+
* **Depth is relative to the anchor, not to the file.** The spec's prototype
|
|
21
|
+
* counted from file start, which is indistinguishable from anchor-relative for
|
|
22
|
+
* the top-level symbols it was measured on — every one sits at depth 0. It is
|
|
23
|
+
* wrong for any nested target: a key inside `"scripts"`, a method in a class, a
|
|
24
|
+
* rule inside `@media`. `packages/lumina/styles/runes/hint.css` is the live
|
|
25
|
+
* proof: the file is wrapped in `@layer skin {`, so `.rf-hint` sits at depth 1
|
|
26
|
+
* and absolute counting returns the whole file instead of the rule.
|
|
27
|
+
*
|
|
28
|
+
* **Reaching EOF is a refusal, never a return.** Returning the remainder is
|
|
29
|
+
* precisely the plausible-wrong render this spec exists to prevent (D4).
|
|
30
|
+
*/
|
|
31
|
+
import { docHeadStart, escapeRegExp, isRangeMasked, maskComments, maskSource, symbolAnchorPattern, } from './mask.js';
|
|
32
|
+
/** Raised for every refusal. The message names the file, the anchor, the
|
|
33
|
+
* reason and the fallback, per D4. */
|
|
34
|
+
export class AnchorResolutionError extends Error {
|
|
35
|
+
constructor(message) {
|
|
36
|
+
super(message);
|
|
37
|
+
this.name = 'AnchorResolutionError';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** The fallback clause every refusal ends with (D4). A refusal that does not
|
|
41
|
+
* say what to do instead is a dead end. */
|
|
42
|
+
function fallbackAdvice() {
|
|
43
|
+
return ('Use `until="…"` or `through="…"` to end the extent at a regex ' +
|
|
44
|
+
'(`through` includes the matching line, `until` excludes it), or `lines=` to ' +
|
|
45
|
+
'address by line range.');
|
|
46
|
+
}
|
|
47
|
+
function refuse(file, anchorLabel, reason) {
|
|
48
|
+
throw new AnchorResolutionError(`could not resolve ${anchorLabel} in ${file} — ${reason} ${fallbackAdvice()}`);
|
|
49
|
+
}
|
|
50
|
+
/** Absolute character offset of the start of each line. */
|
|
51
|
+
function lineOffsets(source) {
|
|
52
|
+
const offsets = [0];
|
|
53
|
+
for (let i = 0; i < source.length; i++) {
|
|
54
|
+
if (source[i] === '\n')
|
|
55
|
+
offsets.push(i + 1);
|
|
56
|
+
}
|
|
57
|
+
return offsets;
|
|
58
|
+
}
|
|
59
|
+
/** Expand leading tabs and measure the indent column of a line. */
|
|
60
|
+
function indentWidth(line, tabWidth) {
|
|
61
|
+
let width = 0;
|
|
62
|
+
for (const ch of line) {
|
|
63
|
+
if (ch === ' ')
|
|
64
|
+
width++;
|
|
65
|
+
else if (ch === '\t')
|
|
66
|
+
width += tabWidth - (width % tabWidth);
|
|
67
|
+
else
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
return width;
|
|
71
|
+
}
|
|
72
|
+
/** Whether a line is blank or wholly a comment — skipped by continuation
|
|
73
|
+
* lookahead and by `dedent`. */
|
|
74
|
+
function isBlankOrComment(line, lang) {
|
|
75
|
+
const text = line.trim();
|
|
76
|
+
if (text.length === 0)
|
|
77
|
+
return true;
|
|
78
|
+
if (!lang)
|
|
79
|
+
return false;
|
|
80
|
+
if (lang.lineComments.some((p) => text.startsWith(p)))
|
|
81
|
+
return true;
|
|
82
|
+
if (lang.blockComments.some(([open]) => text.startsWith(open)))
|
|
83
|
+
return true;
|
|
84
|
+
// A `*` continuation inside a block comment, recognised only where the
|
|
85
|
+
// language actually has block comments.
|
|
86
|
+
if (lang.blockComments.length > 0 && text.startsWith('*'))
|
|
87
|
+
return true;
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Tokens that mean "the previous line was not finished".
|
|
92
|
+
*
|
|
93
|
+
* Without this lookahead a union type with a comment between members ends
|
|
94
|
+
* early — one of the three termination rules that each cost an iteration of
|
|
95
|
+
* the spec's prototype to find.
|
|
96
|
+
*/
|
|
97
|
+
const CONTINUATION = /^(\||&|\.|\?|:|,|\)|\]|\}|=>|extends\b)/;
|
|
98
|
+
/** Count delimiters on a masked line. */
|
|
99
|
+
function countDelimiters(line) {
|
|
100
|
+
let brace = 0;
|
|
101
|
+
let paren = 0;
|
|
102
|
+
let bracket = 0;
|
|
103
|
+
let semicolonAtDepth = false;
|
|
104
|
+
let closingBraceIndex = -1;
|
|
105
|
+
for (let i = 0; i < line.length; i++) {
|
|
106
|
+
const ch = line[i];
|
|
107
|
+
if (ch === '{')
|
|
108
|
+
brace++;
|
|
109
|
+
else if (ch === '}') {
|
|
110
|
+
brace--;
|
|
111
|
+
if (closingBraceIndex === -1)
|
|
112
|
+
closingBraceIndex = i;
|
|
113
|
+
}
|
|
114
|
+
else if (ch === '(')
|
|
115
|
+
paren++;
|
|
116
|
+
else if (ch === ')')
|
|
117
|
+
paren--;
|
|
118
|
+
else if (ch === '[')
|
|
119
|
+
bracket++;
|
|
120
|
+
else if (ch === ']')
|
|
121
|
+
bracket--;
|
|
122
|
+
else if (ch === ';' && brace === 0 && paren === 0 && bracket === 0) {
|
|
123
|
+
semicolonAtDepth = true;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return { brace, paren, bracket, semicolonAtDepth, closingBraceIndex };
|
|
127
|
+
}
|
|
128
|
+
/** Whether the anchor declares a `type` alias, which never terminates on a
|
|
129
|
+
* brace — a type-level object literal is not a body. */
|
|
130
|
+
function isTypeAlias(line, lang) {
|
|
131
|
+
if (!lang?.keywords.includes('type'))
|
|
132
|
+
return false;
|
|
133
|
+
const modifiers = lang.modifiers.map(escapeRegExp).join('|');
|
|
134
|
+
const prefix = modifiers.length > 0 ? `((${modifiers})\\s+)*` : '';
|
|
135
|
+
return new RegExp(`^\\s*${prefix}type\\s+`).test(line);
|
|
136
|
+
}
|
|
137
|
+
/** Every line whose anchor regex matches outside a masked region. */
|
|
138
|
+
function enumerateMatches(source,
|
|
139
|
+
/** The **comment-only** mask, not the full one — see `maskComments`. A JSON
|
|
140
|
+
* key is a string literal, and rejecting matches inside literals would
|
|
141
|
+
* make every key unaddressable. */
|
|
142
|
+
commentMask, lines, pattern) {
|
|
143
|
+
const offsets = lineOffsets(source);
|
|
144
|
+
const found = [];
|
|
145
|
+
for (let i = 0; i < lines.length; i++) {
|
|
146
|
+
// A fresh regex per line: a caller-supplied `match=` may carry flags,
|
|
147
|
+
// and a sticky or global one would otherwise carry lastIndex across
|
|
148
|
+
// lines and skip matches.
|
|
149
|
+
const re = new RegExp(pattern.source, pattern.flags.replace(/[gy]/g, ''));
|
|
150
|
+
const m = re.exec(lines[i]);
|
|
151
|
+
if (!m)
|
|
152
|
+
continue;
|
|
153
|
+
const from = offsets[i] + m.index;
|
|
154
|
+
if (isRangeMasked(source, commentMask, from, from + m[0].length))
|
|
155
|
+
continue;
|
|
156
|
+
found.push(i);
|
|
157
|
+
}
|
|
158
|
+
return found;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The `auto` extent — delimiter balance.
|
|
162
|
+
*
|
|
163
|
+
* Returns the 0-indexed inclusive end line, or `-1` when the scan reached EOF
|
|
164
|
+
* without terminating.
|
|
165
|
+
*/
|
|
166
|
+
function extentAuto(maskedLines, anchorLine, typeAlias, lang, rawLines) {
|
|
167
|
+
// `auto` is the balanced-delimiter family's strategy. In an
|
|
168
|
+
// indentation-structured or tag-paired language there is no `;` and no
|
|
169
|
+
// matching `}` to find, so the honest answer is to refuse and name the
|
|
170
|
+
// strategy that fits — not to let the brace-less rule below terminate on
|
|
171
|
+
// the first line that happens to sit at the anchor's depth, which in
|
|
172
|
+
// Python is the very next one.
|
|
173
|
+
if (!lang?.delimited)
|
|
174
|
+
return -1;
|
|
175
|
+
let brace = 0;
|
|
176
|
+
let paren = 0;
|
|
177
|
+
let bracket = 0;
|
|
178
|
+
let openedBrace = false;
|
|
179
|
+
for (let i = anchorLine; i < maskedLines.length; i++) {
|
|
180
|
+
const counts = countDelimiters(maskedLines[i]);
|
|
181
|
+
// A `;` at anchor depth terminates — but only when nothing this line
|
|
182
|
+
// opened is still open, which `countDelimiters` already accounts for by
|
|
183
|
+
// tracking depth within the line.
|
|
184
|
+
const braceBefore = brace;
|
|
185
|
+
brace += counts.brace;
|
|
186
|
+
paren += counts.paren;
|
|
187
|
+
bracket += counts.bracket;
|
|
188
|
+
if (braceBefore === 0 && counts.brace > 0)
|
|
189
|
+
openedBrace = true;
|
|
190
|
+
// Rule 1 — `}` closing a brace block opened at anchor depth. Parens and
|
|
191
|
+
// brackets nest but never end a statement. Suppressed for `type`.
|
|
192
|
+
if (!typeAlias && openedBrace && brace === 0 && paren === 0 && bracket === 0) {
|
|
193
|
+
return i;
|
|
194
|
+
}
|
|
195
|
+
// Rule 2 — `;` at anchor depth.
|
|
196
|
+
if (counts.semicolonAtDepth && brace === 0 && paren === 0 && bracket === 0) {
|
|
197
|
+
return i;
|
|
198
|
+
}
|
|
199
|
+
// Rule 3 — a brace-less statement ends at the first line back at anchor
|
|
200
|
+
// depth that is not followed by a continuation.
|
|
201
|
+
if (!openedBrace && brace === 0 && paren === 0 && bracket === 0 && i > anchorLine) {
|
|
202
|
+
let j = i + 1;
|
|
203
|
+
while (j < rawLines.length && isBlankOrComment(rawLines[j], lang))
|
|
204
|
+
j++;
|
|
205
|
+
if (j >= rawLines.length)
|
|
206
|
+
return i;
|
|
207
|
+
if (!CONTINUATION.test(rawLines[j].trim()))
|
|
208
|
+
return i;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return -1;
|
|
212
|
+
}
|
|
213
|
+
/** The `dedent` extent — consume blank lines and lines indented deeper than
|
|
214
|
+
* the anchor. For Python, YAML, and anything else where indentation carries
|
|
215
|
+
* the block. */
|
|
216
|
+
function extentDedent(rawLines, anchorLine, lang) {
|
|
217
|
+
const tabWidth = lang?.tabWidth ?? 4;
|
|
218
|
+
const anchorIndent = indentWidth(rawLines[anchorLine], tabWidth);
|
|
219
|
+
let end = anchorLine;
|
|
220
|
+
for (let i = anchorLine + 1; i < rawLines.length; i++) {
|
|
221
|
+
if (rawLines[i].trim().length === 0)
|
|
222
|
+
continue; // blank lines do not end it
|
|
223
|
+
if (indentWidth(rawLines[i], tabWidth) > anchorIndent) {
|
|
224
|
+
end = i;
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
return end;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* The `section` extent — consume forward to the next sibling at the anchor's
|
|
233
|
+
* own level.
|
|
234
|
+
*
|
|
235
|
+
* The terminator is **derived from the anchor line** rather than supplied by
|
|
236
|
+
* the author: a `###` heading ends at the next `^#{1,3}\s`, a `[tool.poetry]`
|
|
237
|
+
* table at the next `^\[`. Anchor on a `###` and an author-written `^## ` is
|
|
238
|
+
* simply wrong, which is why this is a strategy rather than a burden.
|
|
239
|
+
*/
|
|
240
|
+
function extentSection(rawLines, maskedLines, anchorLine, lang) {
|
|
241
|
+
if (!lang || lang.headings.length === 0)
|
|
242
|
+
return undefined;
|
|
243
|
+
for (const heading of lang.headings) {
|
|
244
|
+
const re = new RegExp(heading.pattern);
|
|
245
|
+
const m = re.exec(rawLines[anchorLine]);
|
|
246
|
+
if (!m)
|
|
247
|
+
continue;
|
|
248
|
+
const level = (m[1] ?? '').length;
|
|
249
|
+
for (let i = anchorLine + 1; i < rawLines.length; i++) {
|
|
250
|
+
// Siblings are sought in the **masked** text: a `## ` inside a
|
|
251
|
+
// fenced example is not a heading, and treating it as one truncates
|
|
252
|
+
// the section at the first code block that shows one.
|
|
253
|
+
const sib = re.exec(maskedLines[i]);
|
|
254
|
+
if (!sib)
|
|
255
|
+
continue;
|
|
256
|
+
if ((sib[1] ?? '').length <= level)
|
|
257
|
+
return i - 1;
|
|
258
|
+
}
|
|
259
|
+
return rawLines.length - 1;
|
|
260
|
+
}
|
|
261
|
+
return undefined;
|
|
262
|
+
}
|
|
263
|
+
/** The `paired` extent — balance a matching token pair rather than a
|
|
264
|
+
* delimiter. Handles the three token shapes the table distinguishes. */
|
|
265
|
+
function extentPaired(rawLines, maskedLines, anchorLine, lang) {
|
|
266
|
+
if (!lang || lang.tokenPairs.length === 0)
|
|
267
|
+
return undefined;
|
|
268
|
+
const anchorText = rawLines[anchorLine];
|
|
269
|
+
// Self-closing first: there is no close token, so a scan would run to EOF.
|
|
270
|
+
for (const pair of lang.tokenPairs) {
|
|
271
|
+
if (pair.shape !== 'selfClosing')
|
|
272
|
+
continue;
|
|
273
|
+
if (pair.close.length > 0 && anchorText.includes(pair.close))
|
|
274
|
+
return anchorLine;
|
|
275
|
+
}
|
|
276
|
+
for (const pair of lang.tokenPairs) {
|
|
277
|
+
if (pair.shape === 'selfClosing')
|
|
278
|
+
continue;
|
|
279
|
+
if (!anchorText.includes(pair.open))
|
|
280
|
+
continue;
|
|
281
|
+
if (pair.shape === 'symmetric') {
|
|
282
|
+
// Cannot nest — the first recurrence closes. Fence markers survive
|
|
283
|
+
// masking, so the masked text is the right thing to scan.
|
|
284
|
+
for (let i = anchorLine + 1; i < rawLines.length; i++) {
|
|
285
|
+
if (maskedLines[i].includes(pair.open))
|
|
286
|
+
return i;
|
|
287
|
+
}
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
290
|
+
// Asymmetric and nestable — count depth on the **masked** text, so a
|
|
291
|
+
// `{% tab %}` inside an inline code span does not move the count. The
|
|
292
|
+
// anchor line itself is read raw, since that is what the author matched.
|
|
293
|
+
let depth = 0;
|
|
294
|
+
for (let i = anchorLine; i < rawLines.length; i++) {
|
|
295
|
+
const text = i === anchorLine ? rawLines[i] : maskedLines[i];
|
|
296
|
+
const closes = occurrences(text, pair.close);
|
|
297
|
+
// An open token is only an open when it is not the close token's
|
|
298
|
+
// own prefix: `{% /tabs %}` contains `{%`.
|
|
299
|
+
const opens = occurrences(text, pair.open) - closes;
|
|
300
|
+
depth += opens - closes;
|
|
301
|
+
if (i > anchorLine || opens > 0) {
|
|
302
|
+
if (depth <= 0)
|
|
303
|
+
return i;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return undefined;
|
|
307
|
+
}
|
|
308
|
+
return undefined;
|
|
309
|
+
}
|
|
310
|
+
function occurrences(haystack, needle) {
|
|
311
|
+
if (needle.length === 0)
|
|
312
|
+
return 0;
|
|
313
|
+
let count = 0;
|
|
314
|
+
let idx = haystack.indexOf(needle);
|
|
315
|
+
while (idx !== -1) {
|
|
316
|
+
count++;
|
|
317
|
+
idx = haystack.indexOf(needle, idx + needle.length);
|
|
318
|
+
}
|
|
319
|
+
return count;
|
|
320
|
+
}
|
|
321
|
+
/** Re-mask the extracted slice and verify `{}`, `()` and `[]` all balance.
|
|
322
|
+
* Required for `auto`, and **inert everywhere else** — D2. */
|
|
323
|
+
function isBalanced(slice, lang) {
|
|
324
|
+
const masked = maskSource(slice, lang);
|
|
325
|
+
let brace = 0;
|
|
326
|
+
let paren = 0;
|
|
327
|
+
let bracket = 0;
|
|
328
|
+
for (const ch of masked) {
|
|
329
|
+
if (ch === '{')
|
|
330
|
+
brace++;
|
|
331
|
+
else if (ch === '}')
|
|
332
|
+
brace--;
|
|
333
|
+
else if (ch === '(')
|
|
334
|
+
paren++;
|
|
335
|
+
else if (ch === ')')
|
|
336
|
+
paren--;
|
|
337
|
+
else if (ch === '[')
|
|
338
|
+
bracket++;
|
|
339
|
+
else if (ch === ']')
|
|
340
|
+
bracket--;
|
|
341
|
+
if (brace < 0 || paren < 0 || bracket < 0)
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
return brace === 0 && paren === 0 && bracket === 0;
|
|
345
|
+
}
|
|
346
|
+
/** Annotations attach to the declaration **always**, independent of `doc`: a
|
|
347
|
+
* class quoted without its decorator is wrong in a way a class quoted without
|
|
348
|
+
* its doc comment is not. */
|
|
349
|
+
function absorbAnnotations(lines, line, lang) {
|
|
350
|
+
if (!lang || lang.annotations.length === 0)
|
|
351
|
+
return line;
|
|
352
|
+
let start = line;
|
|
353
|
+
for (let i = line - 1; i >= 0; i--) {
|
|
354
|
+
const text = lines[i].trim();
|
|
355
|
+
if (text.length === 0)
|
|
356
|
+
break;
|
|
357
|
+
if (!lang.annotations.some((a) => text.startsWith(a)))
|
|
358
|
+
break;
|
|
359
|
+
// A line opening a block is a wrapper, not a decoration.
|
|
360
|
+
if (text.endsWith('{'))
|
|
361
|
+
break;
|
|
362
|
+
start = i;
|
|
363
|
+
}
|
|
364
|
+
return start;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Resolve an anchor to a line range.
|
|
368
|
+
*
|
|
369
|
+
* @param source Raw file text.
|
|
370
|
+
* @param lang The language's lexical definition, or `undefined` when the
|
|
371
|
+
* language is absent from the table.
|
|
372
|
+
* @param opts The authored attributes.
|
|
373
|
+
* @param file Path used in refusal messages.
|
|
374
|
+
*/
|
|
375
|
+
export function resolveAnchor(source, lang, opts, file) {
|
|
376
|
+
const warnings = [];
|
|
377
|
+
const rawLines = source.split('\n');
|
|
378
|
+
// Two masks, answering two different questions. `masked` blanks every
|
|
379
|
+
// literal and is what the depth counter reads; `commentMask` blanks only
|
|
380
|
+
// commentary and is what the anchor step rejects against.
|
|
381
|
+
const masked = maskSource(source, lang);
|
|
382
|
+
const maskedLines = masked.split('\n');
|
|
383
|
+
const commentMask = maskComments(source, lang);
|
|
384
|
+
const usingSymbol = typeof opts.symbol === 'string' && opts.symbol.length > 0;
|
|
385
|
+
const usingMatch = typeof opts.match === 'string' && opts.match.length > 0;
|
|
386
|
+
if (usingSymbol && usingMatch) {
|
|
387
|
+
throw new AnchorResolutionError(`snippet \`symbol\` and \`match\` are mutually exclusive — ${file} sets both. ` +
|
|
388
|
+
'`symbol` names a declaration; `match` is a raw regex.');
|
|
389
|
+
}
|
|
390
|
+
const anchorLabel = usingSymbol ? `symbol "${opts.symbol}"` : `match /${opts.match}/`;
|
|
391
|
+
// --- Build the anchor pattern ------------------------------------------
|
|
392
|
+
let pattern;
|
|
393
|
+
if (usingSymbol) {
|
|
394
|
+
const src = symbolAnchorPattern(opts.symbol, lang);
|
|
395
|
+
if (!src) {
|
|
396
|
+
refuse(file, anchorLabel, `this language declares no \`symbol\` keywords, so a named declaration cannot be located.`);
|
|
397
|
+
}
|
|
398
|
+
pattern = new RegExp(src);
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
try {
|
|
402
|
+
pattern = new RegExp(opts.match);
|
|
403
|
+
}
|
|
404
|
+
catch (err) {
|
|
405
|
+
throw new AnchorResolutionError(`snippet \`match\` value /${opts.match}/ is not a valid regular expression: ` +
|
|
406
|
+
`${err.message}`);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
// --- Enumerate every match once; the warning and `occurrence` both read
|
|
410
|
+
// --- from this one list, so they cannot disagree (D14 + D17).
|
|
411
|
+
const matches = enumerateMatches(source, commentMask, rawLines, pattern);
|
|
412
|
+
if (matches.length === 0) {
|
|
413
|
+
refuse(file, anchorLabel, 'no line matches the anchor.');
|
|
414
|
+
}
|
|
415
|
+
if (matches.length > 1) {
|
|
416
|
+
const where = matches.map((i) => `${file}:${i + 1}`).join(', ');
|
|
417
|
+
warnings.push(`snippet anchor ${anchorLabel} is ambiguous in ${file} — ${matches.length} lines match ` +
|
|
418
|
+
`(${where}). Taking ${opts.occurrence ? `occurrence ${opts.occurrence}` : 'the first'}. ` +
|
|
419
|
+
'Use a more specific `match=` regex, or `occurrence=` to select one.');
|
|
420
|
+
}
|
|
421
|
+
const occurrence = opts.occurrence ?? 1;
|
|
422
|
+
if (!Number.isInteger(occurrence) || occurrence < 1) {
|
|
423
|
+
throw new AnchorResolutionError(`snippet \`occurrence\` must be a positive integer, got ${String(opts.occurrence)}.`);
|
|
424
|
+
}
|
|
425
|
+
if (occurrence > matches.length) {
|
|
426
|
+
// Never clamp to the last and never fall back to the first — a clamp is
|
|
427
|
+
// the plausible-wrong render this spec exists to prevent (D17).
|
|
428
|
+
const where = matches.map((i) => `${file}:${i + 1}`).join(', ');
|
|
429
|
+
refuse(file, anchorLabel, `\`occurrence=${occurrence}\` was requested but only ${matches.length} ` +
|
|
430
|
+
`match${matches.length === 1 ? '' : 'es'} exist${matches.length === 1 ? 's' : ''} (${where}).`);
|
|
431
|
+
}
|
|
432
|
+
const anchorLine = matches[occurrence - 1];
|
|
433
|
+
// --- Extent -------------------------------------------------------------
|
|
434
|
+
const strategy = opts.extent ?? 'auto';
|
|
435
|
+
let end;
|
|
436
|
+
let selfCheck = false;
|
|
437
|
+
const hasUntil = typeof opts.until === 'string' && opts.until.length > 0;
|
|
438
|
+
const hasThrough = typeof opts.through === 'string' && opts.through.length > 0;
|
|
439
|
+
if (hasUntil && hasThrough) {
|
|
440
|
+
throw new AnchorResolutionError(`snippet \`until\` and \`through\` are mutually exclusive — ${file} sets both. ` +
|
|
441
|
+
'`through` includes the matching line; `until` excludes it.');
|
|
442
|
+
}
|
|
443
|
+
if (hasUntil || hasThrough) {
|
|
444
|
+
// D12 — two attributes on purpose. `until="^}"` in code wants the
|
|
445
|
+
// terminator line in; `until="^## "` in Markdown wants it out. Either
|
|
446
|
+
// default is silently wrong half the time.
|
|
447
|
+
const raw = (hasThrough ? opts.through : opts.until);
|
|
448
|
+
let terminator;
|
|
449
|
+
try {
|
|
450
|
+
terminator = new RegExp(raw);
|
|
451
|
+
}
|
|
452
|
+
catch (err) {
|
|
453
|
+
throw new AnchorResolutionError(`snippet \`${hasThrough ? 'through' : 'until'}\` value /${raw}/ is not a valid ` +
|
|
454
|
+
`regular expression: ${err.message}`);
|
|
455
|
+
}
|
|
456
|
+
let found = -1;
|
|
457
|
+
for (let i = anchorLine + 1; i < rawLines.length; i++) {
|
|
458
|
+
if (terminator.test(rawLines[i])) {
|
|
459
|
+
found = i;
|
|
460
|
+
break;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
if (found === -1) {
|
|
464
|
+
// A fallback that fails silently is worse than no fallback, because
|
|
465
|
+
// every other refusal message points authors at it (D4).
|
|
466
|
+
refuse(file, anchorLabel, `\`${hasThrough ? 'through' : 'until'}="${raw}"\` never matches after the anchor, ` +
|
|
467
|
+
'so the extent has no end.');
|
|
468
|
+
}
|
|
469
|
+
end = hasThrough ? found : found - 1;
|
|
470
|
+
if (end < anchorLine)
|
|
471
|
+
end = anchorLine;
|
|
472
|
+
}
|
|
473
|
+
else if (strategy === 'auto') {
|
|
474
|
+
selfCheck = true;
|
|
475
|
+
const typeAlias = isTypeAlias(rawLines[anchorLine], lang);
|
|
476
|
+
const found = extentAuto(maskedLines, anchorLine, typeAlias, lang, rawLines);
|
|
477
|
+
if (found === -1) {
|
|
478
|
+
// Naming the strategy that fits is the difference between a refusal
|
|
479
|
+
// an author can act on and one they have to research.
|
|
480
|
+
const paired = lang && lang.tokenPairs.length > 0
|
|
481
|
+
? ' This file is tag-paired, so `extent="paired"` is likely what you want.'
|
|
482
|
+
: '';
|
|
483
|
+
refuse(file, anchorLabel, 'the `auto` extent reached end of file without finding a terminator, so the ' +
|
|
484
|
+
'extent is unknown. `auto` balances delimiters, which only ends a construct in a ' +
|
|
485
|
+
'brace-and-semicolon language. If this file is indentation-structured (Python, ' +
|
|
486
|
+
`YAML), use \`extent="dedent"\`.${paired}`);
|
|
487
|
+
}
|
|
488
|
+
end = found;
|
|
489
|
+
}
|
|
490
|
+
else if (strategy === 'dedent') {
|
|
491
|
+
end = extentDedent(rawLines, anchorLine, lang);
|
|
492
|
+
}
|
|
493
|
+
else if (strategy === 'section') {
|
|
494
|
+
const found = extentSection(rawLines, maskedLines, anchorLine, lang);
|
|
495
|
+
if (found === undefined) {
|
|
496
|
+
refuse(file, anchorLabel, '`extent="section"` needs a heading shape for this language, and the anchor line ' +
|
|
497
|
+
'does not match one.');
|
|
498
|
+
}
|
|
499
|
+
end = found;
|
|
500
|
+
}
|
|
501
|
+
else {
|
|
502
|
+
const found = extentPaired(rawLines, maskedLines, anchorLine, lang);
|
|
503
|
+
if (found === undefined) {
|
|
504
|
+
refuse(file, anchorLabel, '`extent="paired"` found no matching close token for the anchor line.');
|
|
505
|
+
}
|
|
506
|
+
end = found;
|
|
507
|
+
}
|
|
508
|
+
// --- Self-check (auto only — D2) ---------------------------------------
|
|
509
|
+
if (selfCheck) {
|
|
510
|
+
const slice = rawLines.slice(anchorLine, end + 1).join('\n');
|
|
511
|
+
if (!isBalanced(slice, lang)) {
|
|
512
|
+
refuse(file, anchorLabel, 'the extracted slice is not delimiter-balanced, so the extent is wrong.');
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
// --- Head ---------------------------------------------------------------
|
|
516
|
+
const annotationStart = absorbAnnotations(rawLines, anchorLine, lang);
|
|
517
|
+
const includeDoc = opts.doc ?? usingSymbol;
|
|
518
|
+
const start = includeDoc ? docHeadStart(rawLines, annotationStart, lang) : annotationStart;
|
|
519
|
+
return { start: start + 1, end: end + 1, warnings };
|
|
520
|
+
}
|
|
521
|
+
//# sourceMappingURL=anchor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anchor.js","sourceRoot":"","sources":["../../src/lib/anchor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGH,OAAO,EACN,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,UAAU,EACV,mBAAmB,GACnB,MAAM,WAAW,CAAC;AA+BnB;uCACuC;AACvC,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC/C,YAAY,OAAe;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACrC,CAAC;CACD;AAED;4CAC4C;AAC5C,SAAS,cAAc;IACtB,OAAO,CACN,gEAAgE;QAChE,8EAA8E;QAC9E,wBAAwB,CACxB,CAAC;AACH,CAAC;AAED,SAAS,MAAM,CAAC,IAAY,EAAE,WAAmB,EAAE,MAAc;IAChE,MAAM,IAAI,qBAAqB,CAC9B,qBAAqB,WAAW,OAAO,IAAI,MAAM,MAAM,IAAI,cAAc,EAAE,EAAE,CAC7E,CAAC;AACH,CAAC;AAED,2DAA2D;AAC3D,SAAS,WAAW,CAAC,MAAc;IAClC,MAAM,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;IACpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,E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E,CACtE,CAAC;QACH,CAAC;QACD,GAAG,GAAG,KAAK,CAAC;IACb,CAAC;IAED,0EAA0E;IAC1E,IAAI,SAAS,EAAE,CAAC;QACf,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,UAAU,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7D,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;YAC9B,MAAM,CACL,IAAI,EACJ,WAAW,EACX,wEAAwE,CACxE,CAAC;QACH,CAAC;IACF,CAAC;IAED,2EAA2E;IAC3E,MAAM,eAAe,GAAG,iBAAiB,CAAC,QAAQ,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;IACtE,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,IAAI,WAAW,CAAC;IAC3C,MAAM,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,EAAE,eAAe,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC;IAE3F,OAAO,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC;AACrD,CAAC"}
|
package/dist/lib/component.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NodeType } from '@refrakt-md/types';
|
|
1
|
+
import type { NodeType } from '@refrakt-md/types';
|
|
2
2
|
import type { Tag, RenderableTreeNodes } from '@markdoc/markdoc';
|
|
3
3
|
import { toKebabCase } from '@refrakt-md/transform';
|
|
4
4
|
import { RenderableNodeCursor } from './renderable.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../src/lib/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"component.d.ts","source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;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAc7C"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The slice an embedded-source invocation resolves to (SPEC-131, SPEC-134).
|
|
3
|
+
*
|
|
4
|
+
* Shared because two features have to agree on it byte for byte: the review
|
|
5
|
+
* marker hashes this slice, and the staleness ranking decides whether a stored
|
|
6
|
+
* marker still certifies the current content. If the two ever resolved a
|
|
7
|
+
* `symbol=` anchor differently, a marker would read as stale on one side and
|
|
8
|
+
* current on the other, and nobody would be able to say which was right.
|
|
9
|
+
*
|
|
10
|
+
* Deliberately string-in, string-out — no filesystem, no git — so it stays in
|
|
11
|
+
* `packages/runes`, which the editor bundles for the browser.
|
|
12
|
+
*/
|
|
13
|
+
/** Read one double-quoted attribute out of a raw Markdoc attribute string. */
|
|
14
|
+
export declare function attrValue(attrs: string, name: string): string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Resolve an invocation's attribute string against the target's source.
|
|
17
|
+
*
|
|
18
|
+
* Returns `undefined` when the anchor refuses — the refusal is SPEC-131's to
|
|
19
|
+
* report, and a caller that treated it as "no content" would double-report it.
|
|
20
|
+
*/
|
|
21
|
+
export declare function sliceForInvocation(attrs: string, path: string, fileSource: string): string | undefined;
|
|
22
|
+
//# sourceMappingURL=invocation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invocation.d.ts","sourceRoot":"","sources":["../../src/lib/invocation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,8EAA8E;AAC9E,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEzE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,GAChB,MAAM,GAAG,SAAS,CA8CpB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The slice an embedded-source invocation resolves to (SPEC-131, SPEC-134).
|
|
3
|
+
*
|
|
4
|
+
* Shared because two features have to agree on it byte for byte: the review
|
|
5
|
+
* marker hashes this slice, and the staleness ranking decides whether a stored
|
|
6
|
+
* marker still certifies the current content. If the two ever resolved a
|
|
7
|
+
* `symbol=` anchor differently, a marker would read as stale on one side and
|
|
8
|
+
* current on the other, and nobody would be able to say which was right.
|
|
9
|
+
*
|
|
10
|
+
* Deliberately string-in, string-out — no filesystem, no git — so it stays in
|
|
11
|
+
* `packages/runes`, which the editor bundles for the browser.
|
|
12
|
+
*/
|
|
13
|
+
import { reindent, shouldReindent } from './present.js';
|
|
14
|
+
import { resolveAnchor } from './anchor.js';
|
|
15
|
+
import { resolveLanguage } from './languages.js';
|
|
16
|
+
/** Read one double-quoted attribute out of a raw Markdoc attribute string. */
|
|
17
|
+
export function attrValue(attrs, name) {
|
|
18
|
+
return new RegExp(`\\b${name}\\s*=\\s*"([^"]*)"`).exec(attrs)?.[1];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Resolve an invocation's attribute string against the target's source.
|
|
22
|
+
*
|
|
23
|
+
* Returns `undefined` when the anchor refuses — the refusal is SPEC-131's to
|
|
24
|
+
* report, and a caller that treated it as "no content" would double-report it.
|
|
25
|
+
*/
|
|
26
|
+
export function sliceForInvocation(attrs, path, fileSource) {
|
|
27
|
+
const symbol = attrValue(attrs, 'symbol');
|
|
28
|
+
const match = attrValue(attrs, 'match');
|
|
29
|
+
const lines = attrValue(attrs, 'lines');
|
|
30
|
+
if (symbol || match) {
|
|
31
|
+
const occurrence = attrValue(attrs, 'occurrence');
|
|
32
|
+
try {
|
|
33
|
+
const resolved = resolveAnchor(fileSource, resolveLanguage(path), {
|
|
34
|
+
symbol,
|
|
35
|
+
match,
|
|
36
|
+
occurrence: occurrence ? Number(occurrence) : undefined,
|
|
37
|
+
extent: attrValue(attrs, 'extent'),
|
|
38
|
+
until: attrValue(attrs, 'until'),
|
|
39
|
+
through: attrValue(attrs, 'through'),
|
|
40
|
+
doc: /\bdoc\s*=\s*true/.test(attrs)
|
|
41
|
+
? true
|
|
42
|
+
: /\bdoc\s*=\s*false/.test(attrs)
|
|
43
|
+
? false
|
|
44
|
+
: undefined,
|
|
45
|
+
}, path);
|
|
46
|
+
const raw = fileSource
|
|
47
|
+
.split('\n')
|
|
48
|
+
.slice(resolved.start - 1, resolved.end)
|
|
49
|
+
.join('\n');
|
|
50
|
+
return shouldReindent(true, undefined) ? reindent(raw) : raw;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (lines) {
|
|
57
|
+
const m = /^(\d*)-?(\d*)$/.exec(lines.trim());
|
|
58
|
+
if (!m)
|
|
59
|
+
return undefined;
|
|
60
|
+
const all = fileSource.split('\n');
|
|
61
|
+
const start = m[1] ? Number(m[1]) : 1;
|
|
62
|
+
const end = m[2] ? Number(m[2]) : start;
|
|
63
|
+
return all.slice(start - 1, end).join('\n');
|
|
64
|
+
}
|
|
65
|
+
return fileSource;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=invocation.js.map
|