@pretextbook/markdown-style-pretext 0.0.1 → 0.1.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 +0 -0
- package/package.json +3 -3
- package/src/completions/get-completions.spec.ts +14 -0
- package/src/completions/get-completions.ts +4 -0
- package/src/completions/snippets.ts +0 -0
- package/src/data/data.spec.ts +21 -0
- package/src/data/directives.drift.spec.ts +0 -0
- package/src/data/directives.ts +30 -11
- package/src/data/math.ts +0 -0
- package/src/index.ts +0 -0
- package/src/language.ts +0 -0
- package/src/lint/get-diagnostics.spec.ts +0 -0
- package/src/lint/get-diagnostics.ts +0 -0
- package/src/scan/scan-document.spec.ts +0 -0
- package/src/scan/scan-document.ts +0 -0
- package/src/types.ts +0 -0
- package/src/util/position.ts +0 -0
package/README.md
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pretextbook/markdown-style-pretext",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Editor intelligence (completions + validation) for Markdown-style PreTeXt documents",
|
|
5
5
|
"author": "Oscar Levin",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"test": "vitest run"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@pretextbook/latex-style-pretext": "^0.0
|
|
37
|
+
"@pretextbook/latex-style-pretext": "^0.1.0",
|
|
38
38
|
"vscode-languageserver-types": "^3.17.5"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@pretextbook/remark-pretext": "^0.0.
|
|
41
|
+
"@pretextbook/remark-pretext": "^0.0.12"
|
|
42
42
|
},
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
@@ -76,6 +76,20 @@ describe("leaf directive completions", () => {
|
|
|
76
76
|
// `proof` is a container directive; it must not appear in leaf context.
|
|
77
77
|
expect(labels(complete("::pro|"))).not.toContain("proof");
|
|
78
78
|
});
|
|
79
|
+
|
|
80
|
+
it("offers the full plus include vocabulary shared with \\plus", () => {
|
|
81
|
+
const names = labels(complete("::|"));
|
|
82
|
+
expect(names).toContain("appendix");
|
|
83
|
+
expect(names).toContain("worksheet");
|
|
84
|
+
expect(names).toContain("latex-image");
|
|
85
|
+
expect(names).toContain("sageplot");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("sorts divisions ahead of assets", () => {
|
|
89
|
+
const items = complete("::|");
|
|
90
|
+
expect(byLabel(items, "chapter")?.sortText?.startsWith("0")).toBe(true);
|
|
91
|
+
expect(byLabel(items, "image")?.sortText?.startsWith("1")).toBe(true);
|
|
92
|
+
});
|
|
79
93
|
});
|
|
80
94
|
|
|
81
95
|
describe("math completions", () => {
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
import type { GetCompletionsParams } from "../types";
|
|
8
8
|
import { scanDocument, contextAt } from "../scan/scan-document";
|
|
9
9
|
import { CONTAINER_DIRECTIVES, LEAF_DIRECTIVES } from "../data/directives";
|
|
10
|
+
import { PLUS_TYPE_KIND } from "@pretextbook/latex-style-pretext";
|
|
10
11
|
import { KATEX_MACROS, EXTRA_MATH_MACROS } from "../data/math";
|
|
11
12
|
import { rangeFromOffsets } from "../util/position";
|
|
12
13
|
import {
|
|
@@ -179,6 +180,8 @@ function leafItems(
|
|
|
179
180
|
const items: CompletionItem[] = [];
|
|
180
181
|
for (const spec of LEAF_DIRECTIVES) {
|
|
181
182
|
if (prefix && !spec.name.startsWith(prefix)) continue;
|
|
183
|
+
// Divisions sort ahead of assets, matching the LaTeX flavor's `\plus{`.
|
|
184
|
+
const isDivision = PLUS_TYPE_KIND.get(spec.name) === "division";
|
|
182
185
|
items.push(
|
|
183
186
|
makeItem({
|
|
184
187
|
text,
|
|
@@ -188,6 +191,7 @@ function leafItems(
|
|
|
188
191
|
detail: "include · plus:" + spec.name,
|
|
189
192
|
documentation: spec.documentation,
|
|
190
193
|
insert: leafInsertText(spec),
|
|
194
|
+
sortText: `${isDivision ? "0" : "1"}${spec.name}`,
|
|
191
195
|
}),
|
|
192
196
|
);
|
|
193
197
|
}
|
|
File without changes
|
package/src/data/data.spec.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
isKnownContainerDirective,
|
|
7
7
|
} from "./directives";
|
|
8
8
|
import { isKnownMathMacro, isKnownMathEnvironment } from "./math";
|
|
9
|
+
import { PLUS_TYPES } from "@pretextbook/latex-style-pretext";
|
|
9
10
|
|
|
10
11
|
describe("container directive table", () => {
|
|
11
12
|
it("resolves canonical directive names", () => {
|
|
@@ -54,6 +55,26 @@ describe("leaf (include) directives", () => {
|
|
|
54
55
|
// Leaf names are includes: they are not container directives.
|
|
55
56
|
expect(isKnownContainerDirective("image")).toBe(false);
|
|
56
57
|
});
|
|
58
|
+
|
|
59
|
+
it("offers the same include vocabulary as the LaTeX flavor's \\plus", () => {
|
|
60
|
+
const names = LEAF_DIRECTIVES.map((d) => d.name);
|
|
61
|
+
expect(names).toEqual(expect.arrayContaining([...PLUS_TYPES]));
|
|
62
|
+
// Kinds the converter's `defaultPlusTypes` omits stay markdown-only.
|
|
63
|
+
expect(names).toContain("figure");
|
|
64
|
+
expect(PLUS_TYPES).not.toContain("figure");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("describes divisions and assets differently", () => {
|
|
68
|
+
const byName = (name: string) =>
|
|
69
|
+
LEAF_DIRECTIVES.find((d) => d.name === name);
|
|
70
|
+
expect(byName("chapter")?.documentation).toContain("division");
|
|
71
|
+
expect(byName("image")?.documentation).toContain("asset");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("has no duplicate include names", () => {
|
|
75
|
+
const names = LEAF_DIRECTIVES.map((d) => d.name);
|
|
76
|
+
expect(new Set(names).size).toBe(names.length);
|
|
77
|
+
});
|
|
57
78
|
});
|
|
58
79
|
|
|
59
80
|
describe("shared math support", () => {
|
|
File without changes
|
package/src/data/directives.ts
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
// - TEXT directives (`:name[…]`) have no converter handler yet (they become
|
|
15
15
|
// `<TODO>` placeholders), so this package neither completes nor lints them.
|
|
16
16
|
|
|
17
|
+
import { PLUS_TYPES, PLUS_TYPE_KIND } from "@pretextbook/latex-style-pretext";
|
|
17
18
|
import type { DirectiveSpec, DirectiveCategory } from "../types";
|
|
18
19
|
|
|
19
20
|
/** The mirror of `DIRECTIVE_SPEC_TABLE`, minus fields we derive below. */
|
|
@@ -132,29 +133,47 @@ export const CONTAINER_DIRECTIVES: DirectiveSpec[] = Object.entries(
|
|
|
132
133
|
CONTAINER_SEEDS,
|
|
133
134
|
).map(([name, seed]) => seedToSpec(name, seed));
|
|
134
135
|
|
|
136
|
+
/**
|
|
137
|
+
* Include kinds offered by this flavor but absent from the LaTeX converter's
|
|
138
|
+
* `defaultPlusTypes`. Harmless here (any leaf name converts), but the LaTeX
|
|
139
|
+
* flavor validates `\plus{type}` against that list, so `::figure{ref="x"}`
|
|
140
|
+
* completes while `\plus{figure}{x}` warns. Resolve by adding them upstream in
|
|
141
|
+
* `unified-latex/.../pre-conversion-subs/plus-subs.ts` if PreTeXt Plus really
|
|
142
|
+
* includes figures and tables by reference.
|
|
143
|
+
*/
|
|
144
|
+
const MARKDOWN_ONLY_TYPES = ["figure", "table"];
|
|
145
|
+
|
|
146
|
+
function leafDocumentation(name: string): string {
|
|
147
|
+
switch (PLUS_TYPE_KIND.get(name)) {
|
|
148
|
+
case "division":
|
|
149
|
+
return `Include the modular \`${name}\` division stored under \`ref\`.`;
|
|
150
|
+
case "asset":
|
|
151
|
+
return `Include the \`${name}\` asset by \`ref\`.`;
|
|
152
|
+
default:
|
|
153
|
+
return `Include the \`${name}\` element by \`ref\`.`;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
135
157
|
/**
|
|
136
158
|
* Convenience completion list for leaf directives (`::name{…}`). These are the
|
|
137
159
|
* PreTeXt Plus *include* syntax — a reference expanded by a later assembly step
|
|
138
160
|
* (`::section{ref="ch-intro"}` → `<plus:section ref="ch-intro"/>`). Any name is
|
|
139
161
|
* valid, so this list is offered as suggestions but never used for validation.
|
|
162
|
+
*
|
|
163
|
+
* The kinds come from `@pretextbook/latex-style-pretext` so the two flavors
|
|
164
|
+
* suggest one vocabulary; that package mirrors (and drift-tests against) the
|
|
165
|
+
* converter's `defaultPlusTypes`.
|
|
140
166
|
*/
|
|
141
167
|
export const LEAF_DIRECTIVES: DirectiveSpec[] = [
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
["subsection", "Include a modular subsection."],
|
|
146
|
-
["subsubsection", "Include a modular subsubsection."],
|
|
147
|
-
["image", "Include an image asset by `ref`."],
|
|
148
|
-
["listing", "Include a code listing by `ref`."],
|
|
149
|
-
["figure", "Include a figure by `ref`."],
|
|
150
|
-
["table", "Include a table by `ref`."],
|
|
151
|
-
].map(([name, documentation]) => ({
|
|
168
|
+
...PLUS_TYPES,
|
|
169
|
+
...MARKDOWN_ONLY_TYPES,
|
|
170
|
+
].map((name) => ({
|
|
152
171
|
name,
|
|
153
172
|
type: name,
|
|
154
173
|
category: "remark-like" as DirectiveCategory,
|
|
155
174
|
kind: "leaf" as const,
|
|
156
175
|
requiresStatement: false,
|
|
157
|
-
documentation,
|
|
176
|
+
documentation: leafDocumentation(name),
|
|
158
177
|
}));
|
|
159
178
|
|
|
160
179
|
/** Lookup from a container directive name to its spec. */
|
package/src/data/math.ts
CHANGED
|
File without changes
|
package/src/index.ts
CHANGED
|
File without changes
|
package/src/language.ts
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/src/types.ts
CHANGED
|
File without changes
|
package/src/util/position.ts
CHANGED
|
File without changes
|