sfora-cli 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +139 -0
- package/dist/SforaFs.js +8 -6
- package/dist/api-client.d.ts +243 -4
- package/dist/api-client.js +248 -20
- package/dist/block-commands.d.ts +84 -0
- package/dist/block-commands.js +155 -0
- package/dist/cli.js +317 -26
- package/dist/format/blockSplice.d.ts +135 -0
- package/dist/format/blockSplice.js +330 -0
- package/dist/format/blocks/dropClosure.d.ts +10 -1
- package/dist/format/blocks/dropClosure.js +11 -1
- package/dist/format/callout.d.ts +69 -7
- package/dist/format/callout.js +112 -15
- package/dist/format/checklist.js +11 -4
- package/dist/format/formatAxes.d.ts +228 -0
- package/dist/format/formatAxes.js +454 -0
- package/dist/format/index.d.ts +1 -0
- package/dist/format/index.js +4 -0
- package/dist/format/lineGeometry.d.ts +34 -4
- package/dist/format/lineGeometry.js +140 -40
- package/dist/format/lint/appliesTo.d.ts +92 -0
- package/dist/format/lint/appliesTo.js +369 -0
- package/dist/format/lint/config.d.ts +106 -0
- package/dist/format/lint/config.js +205 -0
- package/dist/format/lint/fixAll.d.ts +62 -0
- package/dist/format/lint/fixAll.js +107 -0
- package/dist/format/lint/frontmatterSchema.d.ts +181 -0
- package/dist/format/lint/frontmatterSchema.js +660 -0
- package/dist/format/lint/index.d.ts +34 -5
- package/dist/format/lint/index.js +34 -5
- package/dist/format/lint/lintSource.d.ts +27 -7
- package/dist/format/lint/lintSource.js +67 -33
- package/dist/format/lint/rules/frontmatter-schema.d.ts +2 -0
- package/dist/format/lint/rules/frontmatter-schema.js +92 -0
- package/dist/format/lint/rules/index.d.ts +2 -1
- package/dist/format/lint/rules/index.js +7 -1
- package/dist/format/lint/rules/malformed-callout.js +25 -16
- package/dist/format/lint/rules/malformed-checklist.js +8 -3
- package/dist/format/lint/rules/malformed-frontmatter.js +6 -1
- package/dist/format/lint/severity.d.ts +15 -0
- package/dist/format/lint/severity.js +50 -0
- package/dist/format/lint/textEdits.d.ts +86 -0
- package/dist/format/lint/textEdits.js +162 -0
- package/dist/format/lint/types.d.ts +44 -8
- package/dist/format/markdown/slug.d.ts +28 -0
- package/dist/format/markdown/slug.js +63 -0
- package/dist/format/plaintext.js +13 -3
- package/dist/format/sheetCellSpans.d.ts +95 -0
- package/dist/format/sheetCellSpans.js +223 -0
- package/dist/format/sheetSelection.d.ts +136 -0
- package/dist/format/sheetSelection.js +282 -0
- package/dist/format/textStats.d.ts +23 -0
- package/dist/format/textStats.js +80 -0
- package/dist/format/wikiLinks.d.ts +60 -1
- package/dist/format/wikiLinks.js +195 -9
- package/dist/index.d.ts +26 -1
- package/dist/index.js +20 -3
- package/dist/opener.d.ts +23 -0
- package/dist/opener.js +26 -0
- package/dist/render.d.ts +132 -0
- package/dist/render.js +208 -0
- package/dist/shell-commands.d.ts +34 -0
- package/dist/shell-commands.js +108 -0
- package/dist/watch.d.ts +79 -0
- package/dist/watch.js +113 -0
- package/dist/web-url.d.ts +39 -0
- package/dist/web-url.js +63 -0
- package/package.json +1 -1
package/dist/format/checklist.js
CHANGED
|
@@ -26,6 +26,12 @@ const QUOTE_PREFIX_RE = /^(?:[ \t]{0,3}>[ \t]?)*/;
|
|
|
26
26
|
* own container: an unclosed fence inside one ends with the quote and must not
|
|
27
27
|
* swallow the real checkboxes that follow it at top level.
|
|
28
28
|
*
|
|
29
|
+
* It is the whole mask that runs on the stripped lines, not just the fence
|
|
30
|
+
* half, and it cuts both ways: a `<code>` left open inside a blockquote hides
|
|
31
|
+
* the checkbox below it even where the raw scan sees the line plainly, and a
|
|
32
|
+
* ``` inside a quoted comment is comment text rather than a fence, so the task
|
|
33
|
+
* after the `-->` survives. Both are pinned in checklist.test.ts.
|
|
34
|
+
*
|
|
29
35
|
* Depth 0 is left to the caller's raw mask, which already reads those lines
|
|
30
36
|
* with their `>`-looking content intact.
|
|
31
37
|
*/
|
|
@@ -114,10 +120,11 @@ export function scanChecklist(body) {
|
|
|
114
120
|
openIndent = indent;
|
|
115
121
|
const raw = lineText(lines, i);
|
|
116
122
|
const box = CHECKBOX_RE.exec(raw);
|
|
117
|
-
// The
|
|
118
|
-
//
|
|
119
|
-
//
|
|
120
|
-
//
|
|
123
|
+
// The box has to be one of the bytes that render, and it has to be the
|
|
124
|
+
// box the grammar found. Both halves are reachable on one line: with a
|
|
125
|
+
// comment carried down from above, `- [ ] a --> - [ ] b` renders a
|
|
126
|
+
// checkbox, but not the one CHECKBOX_RE anchored at the head of the line,
|
|
127
|
+
// and that is the one a toggle would rewrite. No addressable box, no item.
|
|
121
128
|
if (!box || line[box[1].length] !== "[")
|
|
122
129
|
continue;
|
|
123
130
|
out.push({
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The format degrees of freedom, as a finite list somebody can read in one
|
|
3
|
+
* sitting.
|
|
4
|
+
*
|
|
5
|
+
* ---------------------------------------------------------------------------
|
|
6
|
+
* WHAT AN AXIS IS
|
|
7
|
+
* ---------------------------------------------------------------------------
|
|
8
|
+
*
|
|
9
|
+
* A format axis is a dimension along which the BYTES of a document may vary
|
|
10
|
+
* while its MEANING does not. `*em*` and `_em_` are two points on one axis.
|
|
11
|
+
* So are ` ``` ` and `~~~`, `# T` and `# T #`, a table's `-` and its `---`.
|
|
12
|
+
* Nothing on this list changes what a reader sees; everything on it changes
|
|
13
|
+
* what the file says on disk.
|
|
14
|
+
*
|
|
15
|
+
* The list exists because "lossy" and "byte-identical" are both useless as
|
|
16
|
+
* verdicts on their own. A serializer that reflows a document is not corrupting
|
|
17
|
+
* it, and a round trip that changes six bytes has not necessarily lost
|
|
18
|
+
* anything — but until the six bytes have a NAME, nobody reviewing the diff can
|
|
19
|
+
* tell which of those two sentences is true. Card #288: byte fidelity as a
|
|
20
|
+
* finite reviewable vocabulary, each entry with a witness that runs.
|
|
21
|
+
*
|
|
22
|
+
* The names follow open-knowledge's, whose `parser-drop-closure.ts:22-289`
|
|
23
|
+
* already spends axis ids the same way — `code-fence:char`, `link:title-quote`,
|
|
24
|
+
* `list:item-marker-spacing`, `setext:underline`. Where a name diverges it is
|
|
25
|
+
* because sfora's capture layer draws the line somewhere else, and the axis
|
|
26
|
+
* says so.
|
|
27
|
+
*
|
|
28
|
+
* ---------------------------------------------------------------------------
|
|
29
|
+
* WHERE THE LIST COMES FROM, AND WHY IT CANNOT BE INVENTED
|
|
30
|
+
* ---------------------------------------------------------------------------
|
|
31
|
+
*
|
|
32
|
+
* The axes are not a taxonomy somebody sat down and wrote. They are DERIVED
|
|
33
|
+
* from what the capture layer already records: `GEOMETRY_KEYS` in
|
|
34
|
+
* `editorWalker/sourceGeometry.ts` is the ground truth, and every
|
|
35
|
+
* `<nodeType>.<dataKey>` in it is one axis's `captures` entry. That is the
|
|
36
|
+
* whole discipline — an axis with no capture is a word, and a capture with no
|
|
37
|
+
* axis is a field nobody can name in a review. `__tests__/formatAxes.test.ts`
|
|
38
|
+
* closes the two against each other in both directions, so neither can drift.
|
|
39
|
+
*
|
|
40
|
+
* This file deliberately does NOT import `GEOMETRY_KEYS`. The capture layer
|
|
41
|
+
* lives under `editorWalker/`, which pulls unified and remark-stringify in and
|
|
42
|
+
* is excluded from the CLI sync (`packages/sfora/scripts/sync-format.mjs`);
|
|
43
|
+
* the drop ledger that spends these ids is NOT excluded and must keep
|
|
44
|
+
* compiling in the tarball. So the coupling is a string in a test rather than
|
|
45
|
+
* an import, and the test is what makes the string true.
|
|
46
|
+
*
|
|
47
|
+
* ---------------------------------------------------------------------------
|
|
48
|
+
* THREE CAPTURE LAYERS, ONE VOCABULARY
|
|
49
|
+
* ---------------------------------------------------------------------------
|
|
50
|
+
*
|
|
51
|
+
* Sfora has three places where an author's spelling is read and set aside, and
|
|
52
|
+
* they are not the same machinery:
|
|
53
|
+
*
|
|
54
|
+
* - the mdast geometry capture, which reads spellings off a POSITIONED parse
|
|
55
|
+
* tree and stores them on `node.data` (`layer: "mdast-geometry"`);
|
|
56
|
+
* - the structured-block parsers, which read a fence body line by line and
|
|
57
|
+
* report what they did not keep (`layer: "structured-block"`);
|
|
58
|
+
* - the blank-run plan, which reads the gaps BETWEEN blocks and the runs at
|
|
59
|
+
* the document's own two ends (`layer: "blank-runs"`).
|
|
60
|
+
*
|
|
61
|
+
* The second is why this file is not simply a rename of `GEOMETRY_KEYS`. The
|
|
62
|
+
* wave-1 drop ledger already spends the id `structured-block:entry-bullet` on
|
|
63
|
+
* a chat entry authored `* @mara: …` rather than `- @mara: …`, and that
|
|
64
|
+
* spelling has no `node.data` anywhere — the bullet is dropped, not captured.
|
|
65
|
+
* An axis vocabulary that could not name it would leave the one verdict it was
|
|
66
|
+
* built for pointing at a string nobody defined.
|
|
67
|
+
*
|
|
68
|
+
* The third is here because the list has to cover what the walker REPLAYS, not
|
|
69
|
+
* what one module happens to declare. `blankRuns.ts` writes
|
|
70
|
+
* `sourceBlankLinesBefore` and `sourceEdgeBlankLines`, `emit.ts`'s join reads
|
|
71
|
+
* both back, and an author's double gap between two sections survives a save
|
|
72
|
+
* because of it — a degree of freedom as real as a fence character, and one the
|
|
73
|
+
* first version of this list was silently missing because those two keys are
|
|
74
|
+
* written by the WALKER onto the tree it builds rather than by
|
|
75
|
+
* `captureSourceGeometry` onto a parse, and so are structurally outside
|
|
76
|
+
* `GEOMETRY_KEYS`. Deriving the list from one module's export rather than from
|
|
77
|
+
* the behaviour is exactly how a vocabulary ends up with a hole in it.
|
|
78
|
+
*
|
|
79
|
+
* So the layer is a discriminant and the closure test grades each layer against
|
|
80
|
+
* its own ground truth: the geometry axes against `GEOMETRY_KEYS`, the block
|
|
81
|
+
* axes against the `format-dof-axis` entries of `BLOCK_DROP_ADJUDICATIONS`, and
|
|
82
|
+
* the blank-run axes against the keys a live `captureRootGaps` /
|
|
83
|
+
* `applyRootGaps` pair actually writes over a corpus. That third ground truth
|
|
84
|
+
* is BEHAVIOURAL rather than declarative, and the suite says so: the two keys
|
|
85
|
+
* are declared in a `declare module "mdast"` block, which erases at runtime, so
|
|
86
|
+
* there is no list to import. A key the corpus never provokes would be invisible
|
|
87
|
+
* to it, which is a real limit and not a hidden one.
|
|
88
|
+
*
|
|
89
|
+
* ---------------------------------------------------------------------------
|
|
90
|
+
* WHAT A WITNESS PROVES, AND WHAT IT DOES NOT
|
|
91
|
+
* ---------------------------------------------------------------------------
|
|
92
|
+
*
|
|
93
|
+
* Every axis carries at least one DISCRIMINATION WITNESS: two spellings, `a`
|
|
94
|
+
* and `b`. The name matters, because these are not round-trip witnesses and
|
|
95
|
+
* calling them that would claim the one thing they do not show. The suite
|
|
96
|
+
* asserts three things about each pair, and the third is what stops the list
|
|
97
|
+
* becoming decoration.
|
|
98
|
+
*
|
|
99
|
+
* 1. the bytes differ — otherwise there is no degree of freedom here;
|
|
100
|
+
* 2. an INDEPENDENT reparse reads both to the same tree, positions and
|
|
101
|
+
* `data` stripped (`geometryReparsesTheSame`) — otherwise this is a
|
|
102
|
+
* content difference wearing a formatting name;
|
|
103
|
+
* 3. the capture layer TELLS THEM APART — the set of captured keys that move
|
|
104
|
+
* between `a` and `b` is non-empty, and across an axis's witnesses it
|
|
105
|
+
* covers every key the axis claims.
|
|
106
|
+
*
|
|
107
|
+
* Three is the anti-vacuity clause. An axis whose witnesses no longer move its
|
|
108
|
+
* own capture key is an axis whose capture stopped happening, and the suite
|
|
109
|
+
* fails on the axis rather than on some distant serializer test six months
|
|
110
|
+
* later.
|
|
111
|
+
*
|
|
112
|
+
* What a discrimination witness does NOT prove is that the spelling survives a
|
|
113
|
+
* save. Most of these axes are captured and not yet replayed —
|
|
114
|
+
* `CAPTURED_NOT_REPLAYED` in `sourceGeometry.ts` says which, and names the card
|
|
115
|
+
* that owes each one. The suite pins the replayed SET rather than a total,
|
|
116
|
+
* because a total can hold still while the membership churns — and, for one
|
|
117
|
+
* axis in each replay FAMILY, it serializes an editor document through the real
|
|
118
|
+
* walker and asserts the author's bytes come back. A scoreboard read off a
|
|
119
|
+
* hand-maintained array is a scoreboard that can be wrong in the direction
|
|
120
|
+
* nobody checks.
|
|
121
|
+
*/
|
|
122
|
+
import type { BlockDropReason } from "./blocks/dropClosure.js";
|
|
123
|
+
import type { StructuredBlockLanguage } from "./blocks/structured-block-schema.js";
|
|
124
|
+
/**
|
|
125
|
+
* Every axis id, as a union so a ledger entry citing one that does not exist
|
|
126
|
+
* fails to compile rather than fails to mean anything.
|
|
127
|
+
*
|
|
128
|
+
* `namespace:name`, lower case, and the namespace is the CONSTRUCT rather than
|
|
129
|
+
* the mdast node type where the two disagree — `task-list:checkbox-char` sits
|
|
130
|
+
* on `listItem.sourceCheckboxChar`, and an author who has never heard of mdast
|
|
131
|
+
* still knows what a task list is.
|
|
132
|
+
*/
|
|
133
|
+
export type FormatAxisId = "blank-lines:doc-edge" | "blank-lines:interior" | "block-gap:after-heading" | "blockquote:marker-spacing" | "code-block:style" | "code-fence:char" | "code-fence:info-padding" | "code-fence:length" | "definition:layout" | "definition:title-quote" | "emphasis:delimiter" | "hard-break:style" | "heading:style" | "heading:trailing-hashes" | "inline-code:fence-length" | "inline-code:padding" | "lexical:backslash-escape" | "link:angle-url" | "link:autolink-form" | "link:title-quote" | "list:bullet-marker" | "list:item-marker-spacing" | "list:item-ordinal" | "list:ordered-delimiter" | "setext:underline-length" | "strike:delimiter" | "strong:delimiter" | "structured-block:entry-bullet" | "table:cell-padding" | "table:delimiter-dashes" | "table:delimiter-padding" | "table:outer-pipes" | "task-list:checkbox-char" | "thematic-break:marker";
|
|
134
|
+
/**
|
|
135
|
+
* Two spellings of one meaning, for an axis the mdast geometry layer captures.
|
|
136
|
+
*
|
|
137
|
+
* Both are whole markdown documents rather than fragments, because the capture
|
|
138
|
+
* layer reads source OFFSETS and a fragment has none. They are kept as short as
|
|
139
|
+
* the axis allows so a reader can see the difference without diffing.
|
|
140
|
+
*/
|
|
141
|
+
export interface GeometryAxisWitness {
|
|
142
|
+
a: string;
|
|
143
|
+
b: string;
|
|
144
|
+
/** What moved, in the words a reviewer would use. */
|
|
145
|
+
note: string;
|
|
146
|
+
}
|
|
147
|
+
/** Two spellings of one meaning, for an axis a structured-block parser drops. */
|
|
148
|
+
export interface BlockAxisWitness {
|
|
149
|
+
lang: StructuredBlockLanguage;
|
|
150
|
+
/** The spelling whose bytes survive. */
|
|
151
|
+
a: string;
|
|
152
|
+
/** The spelling that provokes the drop. */
|
|
153
|
+
b: string;
|
|
154
|
+
note: string;
|
|
155
|
+
}
|
|
156
|
+
export type FormatAxis = {
|
|
157
|
+
id: FormatAxisId;
|
|
158
|
+
layer: "mdast-geometry";
|
|
159
|
+
/**
|
|
160
|
+
* `<nodeType>.<dataKey>`, exactly as `GEOMETRY_KEYS` spells it. Every
|
|
161
|
+
* entry must be declared there and every entry there must appear on
|
|
162
|
+
* exactly one axis.
|
|
163
|
+
*/
|
|
164
|
+
captures: readonly string[];
|
|
165
|
+
rationale: string;
|
|
166
|
+
witnesses: readonly GeometryAxisWitness[];
|
|
167
|
+
} | {
|
|
168
|
+
id: FormatAxisId;
|
|
169
|
+
layer: "blank-runs";
|
|
170
|
+
/**
|
|
171
|
+
* The `data` keys `blankRuns.ts` writes, by NAME rather than as
|
|
172
|
+
* `<nodeType>.<dataKey>`.
|
|
173
|
+
*
|
|
174
|
+
* The node type is not part of the identity here and pretending it were
|
|
175
|
+
* would be a lie in the vocabulary: an interior gap belongs to whatever
|
|
176
|
+
* block happens to follow it, so `sourceBlankLinesBefore` lands on a
|
|
177
|
+
* paragraph, a code block or a table depending on the document. (The edge
|
|
178
|
+
* run is always on the root, and is spelled the same way for symmetry.)
|
|
179
|
+
*/
|
|
180
|
+
dataKeys: readonly string[];
|
|
181
|
+
rationale: string;
|
|
182
|
+
witnesses: readonly GeometryAxisWitness[];
|
|
183
|
+
} | {
|
|
184
|
+
id: FormatAxisId;
|
|
185
|
+
layer: "structured-block";
|
|
186
|
+
/**
|
|
187
|
+
* The drop reasons in `BLOCK_DROP_ADJUDICATIONS` whose `format-dof-axis`
|
|
188
|
+
* verdict spends this id. Closed both directions by the suite.
|
|
189
|
+
*/
|
|
190
|
+
ledgerReasons: readonly BlockDropReason[];
|
|
191
|
+
rationale: string;
|
|
192
|
+
witnesses: readonly BlockAxisWitness[];
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* The list. Sorted by id, because a list nobody can scan is not reviewable and
|
|
196
|
+
* reviewable is the entire point.
|
|
197
|
+
*/
|
|
198
|
+
export declare const FORMAT_AXES: readonly FormatAxis[];
|
|
199
|
+
/** Every id on the list, for a cheap membership test. */
|
|
200
|
+
export declare const FORMAT_AXIS_IDS: ReadonlySet<FormatAxisId>;
|
|
201
|
+
/**
|
|
202
|
+
* The axis with this id.
|
|
203
|
+
*
|
|
204
|
+
* Throws rather than returning undefined: every call site here is spending an
|
|
205
|
+
* id that the type system already proved exists, so a miss means the list and
|
|
206
|
+
* the union disagree, which is a bug in this file and not a case a caller
|
|
207
|
+
* should be writing a branch for.
|
|
208
|
+
*/
|
|
209
|
+
export declare function formatAxis(id: FormatAxisId): FormatAxis;
|
|
210
|
+
/**
|
|
211
|
+
* The axis that owns a captured geometry key, spelled `<nodeType>.<dataKey>`.
|
|
212
|
+
*
|
|
213
|
+
* Undefined here is the interesting answer, not an error: it means the capture
|
|
214
|
+
* layer records a spelling the vocabulary cannot name, which is exactly what
|
|
215
|
+
* the closure test is looking for.
|
|
216
|
+
*/
|
|
217
|
+
export declare function axisForCapture(key: string): FormatAxis | undefined;
|
|
218
|
+
/** Every `<nodeType>.<dataKey>` the vocabulary claims, deduplicated. */
|
|
219
|
+
export declare function claimedCaptureKeys(): string[];
|
|
220
|
+
/**
|
|
221
|
+
* Every blank-run `data` key the vocabulary claims, deduplicated.
|
|
222
|
+
*
|
|
223
|
+
* Kept apart from {@link claimedCaptureKeys} rather than merged into it because
|
|
224
|
+
* the two are spelled differently on purpose — one carries a node type and the
|
|
225
|
+
* other cannot — and a single list would have to pick one spelling and be wrong
|
|
226
|
+
* about half its entries.
|
|
227
|
+
*/
|
|
228
|
+
export declare function claimedBlankRunKeys(): string[];
|