@descent-vtt/spec-graph 0.2.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/LICENSE +21 -0
- package/README.md +627 -0
- package/bin/spec-graph.js +24 -0
- package/dist/baseline.d.ts +93 -0
- package/dist/baseline.js +187 -0
- package/dist/baseline.js.map +1 -0
- package/dist/cli.d.ts +66 -0
- package/dist/cli.js +565 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +66 -0
- package/dist/config.js +183 -0
- package/dist/config.js.map +1 -0
- package/dist/directives.d.ts +56 -0
- package/dist/directives.js +125 -0
- package/dist/directives.js.map +1 -0
- package/dist/extract.d.ts +116 -0
- package/dist/extract.js +1043 -0
- package/dist/extract.js.map +1 -0
- package/dist/glob.d.ts +73 -0
- package/dist/glob.js +284 -0
- package/dist/glob.js.map +1 -0
- package/dist/graph.d.ts +55 -0
- package/dist/graph.js +201 -0
- package/dist/graph.js.map +1 -0
- package/dist/identity.d.ts +87 -0
- package/dist/identity.js +294 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/lifecycle.d.ts +57 -0
- package/dist/lifecycle.js +258 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/markdown.d.ts +152 -0
- package/dist/markdown.js +820 -0
- package/dist/markdown.js.map +1 -0
- package/dist/paths.d.ts +22 -0
- package/dist/paths.js +58 -0
- package/dist/paths.js.map +1 -0
- package/dist/report.d.ts +89 -0
- package/dist/report.js +326 -0
- package/dist/report.js.map +1 -0
- package/dist/resolve.d.ts +61 -0
- package/dist/resolve.js +340 -0
- package/dist/resolve.js.map +1 -0
- package/dist/rules.d.ts +61 -0
- package/dist/rules.js +557 -0
- package/dist/rules.js.map +1 -0
- package/dist/runner.d.ts +108 -0
- package/dist/runner.js +186 -0
- package/dist/runner.js.map +1 -0
- package/dist/sections.d.ts +94 -0
- package/dist/sections.js +372 -0
- package/dist/sections.js.map +1 -0
- package/dist/select.d.ts +96 -0
- package/dist/select.js +413 -0
- package/dist/select.js.map +1 -0
- package/dist/source.d.ts +43 -0
- package/dist/source.js +109 -0
- package/dist/source.js.map +1 -0
- package/dist/state.d.ts +45 -0
- package/dist/state.js +330 -0
- package/dist/state.js.map +1 -0
- package/dist/types.d.ts +294 -0
- package/dist/types.js +52 -0
- package/dist/types.js.map +1 -0
- package/dist/yaml.d.ts +37 -0
- package/dist/yaml.js +240 -0
- package/dist/yaml.js.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A structural Markdown scanner.
|
|
3
|
+
*
|
|
4
|
+
* This is deliberately **not** a CommonMark implementation. spec-graph needs six
|
|
5
|
+
* things from a document - front matter, headings, list items with their
|
|
6
|
+
* continuations, HTML comments, links, and a reliable map of what is code - and
|
|
7
|
+
* a full parser would cost a dependency tree, an AST walk, and a position
|
|
8
|
+
* mapping layer to get back the offsets we want in the first place.
|
|
9
|
+
*
|
|
10
|
+
* What the scanner does guarantee is the part that makes regex-based spec
|
|
11
|
+
* linters lie:
|
|
12
|
+
*
|
|
13
|
+
* - **Code never counts.** Fenced blocks, indented blocks and inline spans are
|
|
14
|
+
* masked before a single link is extracted, so an example in a code sample
|
|
15
|
+
* never becomes a graph edge.
|
|
16
|
+
* - **Items are blocks, not lines.** A list item owns its wrapped continuation
|
|
17
|
+
* lines and its nested content, so a resolution written on the second line of
|
|
18
|
+
* a bullet is found instead of missed.
|
|
19
|
+
* - **Everything carries absolute offsets.** No re-scanning, no drift between
|
|
20
|
+
* the text a rule matched and the position it reports.
|
|
21
|
+
*/
|
|
22
|
+
import { type LineIndex } from './source.js';
|
|
23
|
+
export interface Range {
|
|
24
|
+
readonly start: number;
|
|
25
|
+
readonly end: number;
|
|
26
|
+
}
|
|
27
|
+
export interface FrontMatter {
|
|
28
|
+
/** The body between the delimiters, exclusive. */
|
|
29
|
+
readonly raw: string;
|
|
30
|
+
/** Offset of the first character of `raw`. */
|
|
31
|
+
readonly start: number;
|
|
32
|
+
readonly end: number;
|
|
33
|
+
/** Offset just past the closing delimiter line. */
|
|
34
|
+
readonly bodyStart: number;
|
|
35
|
+
}
|
|
36
|
+
export interface ScannedLine {
|
|
37
|
+
/** 1-based. */
|
|
38
|
+
readonly line: number;
|
|
39
|
+
/** Offset of the raw line start. */
|
|
40
|
+
readonly start: number;
|
|
41
|
+
/** Offset just past the line, excluding its terminator. */
|
|
42
|
+
readonly end: number;
|
|
43
|
+
/** Offset of the first character after any block-quote markers. */
|
|
44
|
+
readonly contentStart: number;
|
|
45
|
+
/** Line text after block-quote markers, indentation intact. */
|
|
46
|
+
readonly content: string;
|
|
47
|
+
/** Indentation of `content`, tabs counted as four columns. */
|
|
48
|
+
readonly indent: number;
|
|
49
|
+
readonly blank: boolean;
|
|
50
|
+
readonly quoteDepth: number;
|
|
51
|
+
/** Inside a fenced or indented code block, fence delimiters included. */
|
|
52
|
+
readonly code: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface Heading {
|
|
55
|
+
readonly level: number;
|
|
56
|
+
readonly text: string;
|
|
57
|
+
/** GitHub-compatible anchor slug. */
|
|
58
|
+
readonly slug: string;
|
|
59
|
+
readonly start: number;
|
|
60
|
+
readonly end: number;
|
|
61
|
+
readonly line: number;
|
|
62
|
+
}
|
|
63
|
+
export interface ListItem {
|
|
64
|
+
/** The whole block: marker line plus continuations and nested content. */
|
|
65
|
+
readonly start: number;
|
|
66
|
+
readonly end: number;
|
|
67
|
+
/** Offset of the list marker itself. */
|
|
68
|
+
readonly markerStart: number;
|
|
69
|
+
readonly marker: string;
|
|
70
|
+
/** Offset where the item text begins, after marker and any checkbox. */
|
|
71
|
+
readonly textStart: number;
|
|
72
|
+
/** The character inside `[ ]`, or `null` when the item has no checkbox. */
|
|
73
|
+
readonly checkbox: string | null;
|
|
74
|
+
readonly checkboxStart: number | null;
|
|
75
|
+
/** First line of item text, trimmed. */
|
|
76
|
+
readonly firstLine: string;
|
|
77
|
+
/** Full item text including continuations and nested content. */
|
|
78
|
+
readonly body: string;
|
|
79
|
+
/**
|
|
80
|
+
* `body` with code and comments blanked out, same length and offsets.
|
|
81
|
+
*
|
|
82
|
+
* Anything that searches item text for meaning - resolution markers above
|
|
83
|
+
* all - must read this rather than `body`, or a fenced example nested under
|
|
84
|
+
* the item will close it.
|
|
85
|
+
*/
|
|
86
|
+
readonly maskedBody: string;
|
|
87
|
+
readonly line: number;
|
|
88
|
+
/** How many list items enclose this one. Top-level items are `0`. */
|
|
89
|
+
readonly depth: number;
|
|
90
|
+
readonly indent: number;
|
|
91
|
+
}
|
|
92
|
+
export interface HtmlComment {
|
|
93
|
+
readonly start: number;
|
|
94
|
+
readonly end: number;
|
|
95
|
+
/** Text between `<!--` and `-->`. */
|
|
96
|
+
readonly inner: string;
|
|
97
|
+
readonly innerStart: number;
|
|
98
|
+
readonly line: number;
|
|
99
|
+
}
|
|
100
|
+
export type LinkForm = 'inline' | 'reference' | 'shortcut' | 'autolink' | 'wiki' | 'definition';
|
|
101
|
+
export interface Link {
|
|
102
|
+
/** Visible label. Empty for autolinks and definitions. */
|
|
103
|
+
readonly text: string;
|
|
104
|
+
/** Destination as written: a path, a URL, or a reference label. */
|
|
105
|
+
readonly target: string;
|
|
106
|
+
/** Offset of the whole construct. */
|
|
107
|
+
readonly start: number;
|
|
108
|
+
readonly end: number;
|
|
109
|
+
/** Offset of `target` inside the source, for precise diagnostics. */
|
|
110
|
+
readonly targetStart: number;
|
|
111
|
+
readonly form: LinkForm;
|
|
112
|
+
readonly line: number;
|
|
113
|
+
}
|
|
114
|
+
export interface TableCell {
|
|
115
|
+
/** Cell text as written, trimmed. */
|
|
116
|
+
readonly text: string;
|
|
117
|
+
/** Offset of the trimmed text, so a finding can point at the cell itself. */
|
|
118
|
+
readonly start: number;
|
|
119
|
+
readonly end: number;
|
|
120
|
+
}
|
|
121
|
+
export interface TableRow {
|
|
122
|
+
readonly cells: readonly TableCell[];
|
|
123
|
+
readonly start: number;
|
|
124
|
+
readonly end: number;
|
|
125
|
+
readonly line: number;
|
|
126
|
+
}
|
|
127
|
+
export interface Table {
|
|
128
|
+
readonly start: number;
|
|
129
|
+
readonly end: number;
|
|
130
|
+
/** Header cells, trimmed. A table without a header row is not a table. */
|
|
131
|
+
readonly headers: readonly TableCell[];
|
|
132
|
+
readonly rows: readonly TableRow[];
|
|
133
|
+
}
|
|
134
|
+
export interface ScannedDocument {
|
|
135
|
+
readonly text: string;
|
|
136
|
+
readonly index: LineIndex;
|
|
137
|
+
readonly frontMatter: FrontMatter | null;
|
|
138
|
+
/** Offset where the body starts, after any front matter. */
|
|
139
|
+
readonly bodyStart: number;
|
|
140
|
+
readonly lines: readonly ScannedLine[];
|
|
141
|
+
readonly headings: readonly Heading[];
|
|
142
|
+
readonly listItems: readonly ListItem[];
|
|
143
|
+
readonly comments: readonly HtmlComment[];
|
|
144
|
+
readonly links: readonly Link[];
|
|
145
|
+
readonly tables: readonly Table[];
|
|
146
|
+
/** Code and comments blanked out, offsets and line breaks preserved. */
|
|
147
|
+
readonly masked: string;
|
|
148
|
+
/** True when the offset falls inside code, a comment, or front matter. */
|
|
149
|
+
isMasked(offset: number): boolean;
|
|
150
|
+
}
|
|
151
|
+
export declare function scanMarkdown(source: string): ScannedDocument;
|
|
152
|
+
export declare function slugify(text: string): string;
|