@pretextbook/remark-pretext 0.0.11 → 0.0.12
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 +18 -18
- package/dist/index.js +156 -30
- package/dist/lib/context.d.ts +1 -1
- package/dist/lib/directive-map.d.ts +1 -1
- package/dist/lib/math-parser.d.ts +2 -2
- package/index.cjs +1 -1
- package/index.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -27,18 +27,18 @@ Left as an exercise.
|
|
|
27
27
|
## Usage
|
|
28
28
|
|
|
29
29
|
```ts
|
|
30
|
-
import { unified } from
|
|
31
|
-
import remarkParse from
|
|
32
|
-
import remarkDirective from
|
|
33
|
-
import { remarkPretext } from
|
|
30
|
+
import { unified } from "unified";
|
|
31
|
+
import remarkParse from "remark-parse";
|
|
32
|
+
import remarkDirective from "remark-directive";
|
|
33
|
+
import { remarkPretext } from "@pretextbook/remark-pretext";
|
|
34
34
|
|
|
35
35
|
const processor = unified()
|
|
36
36
|
.use(remarkParse)
|
|
37
|
-
.use(remarkDirective)
|
|
38
|
-
.use(remarkPretext)
|
|
37
|
+
.use(remarkDirective) // enables ::: directives
|
|
38
|
+
.use(remarkPretext);
|
|
39
39
|
|
|
40
|
-
const mdast = processor.parse(markdownString)
|
|
41
|
-
const ptxast = processor.runSync(mdast, { value: markdownString }) // PtxRoot
|
|
40
|
+
const mdast = processor.parse(markdownString);
|
|
41
|
+
const ptxast = processor.runSync(mdast, { value: markdownString }); // PtxRoot
|
|
42
42
|
|
|
43
43
|
// Serialize to XML (use @pretextbook/ptxast-util-to-xml)
|
|
44
44
|
```
|
|
@@ -80,9 +80,9 @@ There are two ways to change it:
|
|
|
80
80
|
precedence over frontmatter when both are present.
|
|
81
81
|
|
|
82
82
|
```ts
|
|
83
|
-
import { markdownToPretext } from
|
|
83
|
+
import { markdownToPretext } from "@pretextbook/remark-pretext";
|
|
84
84
|
|
|
85
|
-
markdownToPretext(
|
|
85
|
+
markdownToPretext("# Title\n\n## Sub", { topLevelDivision: "section" });
|
|
86
86
|
// → '<section><title>Title</title><subsection>...'
|
|
87
87
|
```
|
|
88
88
|
|
|
@@ -196,11 +196,11 @@ when both are present.
|
|
|
196
196
|
|
|
197
197
|
## Supported Directives
|
|
198
198
|
|
|
199
|
-
| Category
|
|
200
|
-
|
|
201
|
-
| theorem-like
|
|
202
|
-
| definition-like | `definition`, `notation`
|
|
203
|
-
| remark-like
|
|
204
|
-
| example-like
|
|
205
|
-
| proof-like
|
|
206
|
-
| solution-like
|
|
199
|
+
| Category | Names |
|
|
200
|
+
| --------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
|
201
|
+
| theorem-like | `theorem`, `lemma`, `corollary`, `proposition`, `claim`, `fact`, `conjecture`, `axiom`, `principle`, `hypothesis`, `algorithm` |
|
|
202
|
+
| definition-like | `definition`, `notation` |
|
|
203
|
+
| remark-like | `remark`, `note`, `observation`, `warning`, `insight`, `assemblage` |
|
|
204
|
+
| example-like | `example`, `question`, `problem`, `exercise`, `activity`, `exploration`, `investigation`, `project` |
|
|
205
|
+
| proof-like | `proof`, `case` |
|
|
206
|
+
| solution-like | `solution`, `hint`, `answer` |
|
package/dist/index.js
CHANGED
|
@@ -20,51 +20,152 @@ function he(e) {
|
|
|
20
20
|
}
|
|
21
21
|
const $ = {
|
|
22
22
|
// theorem-like (requires statement wrapping)
|
|
23
|
-
theorem: {
|
|
23
|
+
theorem: {
|
|
24
|
+
type: "theorem",
|
|
25
|
+
category: "theorem-like",
|
|
26
|
+
requiresStatement: !0
|
|
27
|
+
},
|
|
24
28
|
lemma: { type: "lemma", category: "theorem-like", requiresStatement: !0 },
|
|
25
|
-
corollary: {
|
|
26
|
-
|
|
29
|
+
corollary: {
|
|
30
|
+
type: "corollary",
|
|
31
|
+
category: "theorem-like",
|
|
32
|
+
requiresStatement: !0
|
|
33
|
+
},
|
|
34
|
+
proposition: {
|
|
35
|
+
type: "proposition",
|
|
36
|
+
category: "theorem-like",
|
|
37
|
+
requiresStatement: !0
|
|
38
|
+
},
|
|
27
39
|
claim: { type: "claim", category: "theorem-like", requiresStatement: !0 },
|
|
28
40
|
fact: { type: "fact", category: "theorem-like", requiresStatement: !0 },
|
|
29
|
-
conjecture: {
|
|
41
|
+
conjecture: {
|
|
42
|
+
type: "conjecture",
|
|
43
|
+
category: "theorem-like",
|
|
44
|
+
requiresStatement: !0
|
|
45
|
+
},
|
|
30
46
|
axiom: { type: "axiom", category: "theorem-like", requiresStatement: !0 },
|
|
31
|
-
principle: {
|
|
32
|
-
|
|
33
|
-
|
|
47
|
+
principle: {
|
|
48
|
+
type: "principle",
|
|
49
|
+
category: "theorem-like",
|
|
50
|
+
requiresStatement: !0
|
|
51
|
+
},
|
|
52
|
+
hypothesis: {
|
|
53
|
+
type: "hypothesis",
|
|
54
|
+
category: "theorem-like",
|
|
55
|
+
requiresStatement: !0
|
|
56
|
+
},
|
|
57
|
+
algorithm: {
|
|
58
|
+
type: "algorithm",
|
|
59
|
+
category: "theorem-like",
|
|
60
|
+
requiresStatement: !0
|
|
61
|
+
},
|
|
34
62
|
// definition-like (requires statement wrapping)
|
|
35
|
-
definition: {
|
|
36
|
-
|
|
63
|
+
definition: {
|
|
64
|
+
type: "definition",
|
|
65
|
+
category: "definition-like",
|
|
66
|
+
requiresStatement: !0
|
|
67
|
+
},
|
|
68
|
+
notation: {
|
|
69
|
+
type: "notation",
|
|
70
|
+
category: "definition-like",
|
|
71
|
+
requiresStatement: !0
|
|
72
|
+
},
|
|
37
73
|
// remark-like (no statement wrapping)
|
|
38
74
|
remark: { type: "remark", category: "remark-like", requiresStatement: !1 },
|
|
39
75
|
note: { type: "note", category: "remark-like", requiresStatement: !1 },
|
|
40
|
-
observation: {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
76
|
+
observation: {
|
|
77
|
+
type: "observation",
|
|
78
|
+
category: "remark-like",
|
|
79
|
+
requiresStatement: !1
|
|
80
|
+
},
|
|
81
|
+
warning: {
|
|
82
|
+
type: "warning",
|
|
83
|
+
category: "remark-like",
|
|
84
|
+
requiresStatement: !1
|
|
85
|
+
},
|
|
86
|
+
insight: {
|
|
87
|
+
type: "insight",
|
|
88
|
+
category: "remark-like",
|
|
89
|
+
requiresStatement: !1
|
|
90
|
+
},
|
|
91
|
+
assemblage: {
|
|
92
|
+
type: "assemblage",
|
|
93
|
+
category: "remark-like",
|
|
94
|
+
requiresStatement: !1
|
|
95
|
+
},
|
|
44
96
|
// example-like (exercise/project/task support nested tasks; require statement if no nested tasks)
|
|
45
|
-
example: {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
97
|
+
example: {
|
|
98
|
+
type: "example",
|
|
99
|
+
category: "example-like",
|
|
100
|
+
requiresStatement: !1
|
|
101
|
+
},
|
|
102
|
+
question: {
|
|
103
|
+
type: "question",
|
|
104
|
+
category: "example-like",
|
|
105
|
+
requiresStatement: !1
|
|
106
|
+
},
|
|
107
|
+
problem: {
|
|
108
|
+
type: "problem",
|
|
109
|
+
category: "example-like",
|
|
110
|
+
requiresStatement: !1
|
|
111
|
+
},
|
|
112
|
+
exercise: {
|
|
113
|
+
type: "exercise",
|
|
114
|
+
category: "example-like",
|
|
115
|
+
requiresStatement: !0,
|
|
116
|
+
hasNestedTasks: !0
|
|
117
|
+
},
|
|
118
|
+
activity: {
|
|
119
|
+
type: "activity",
|
|
120
|
+
category: "example-like",
|
|
121
|
+
requiresStatement: !1
|
|
122
|
+
},
|
|
123
|
+
exploration: {
|
|
124
|
+
type: "exploration",
|
|
125
|
+
category: "example-like",
|
|
126
|
+
requiresStatement: !1
|
|
127
|
+
},
|
|
128
|
+
investigation: {
|
|
129
|
+
type: "investigation",
|
|
130
|
+
category: "example-like",
|
|
131
|
+
requiresStatement: !1
|
|
132
|
+
},
|
|
133
|
+
project: {
|
|
134
|
+
type: "project",
|
|
135
|
+
category: "example-like",
|
|
136
|
+
requiresStatement: !0,
|
|
137
|
+
hasNestedTasks: !0
|
|
138
|
+
},
|
|
53
139
|
// task (can have nested tasks, requires statement if no nested tasks)
|
|
54
|
-
task: {
|
|
140
|
+
task: {
|
|
141
|
+
type: "task",
|
|
142
|
+
category: "example-like",
|
|
143
|
+
requiresStatement: !0,
|
|
144
|
+
hasNestedTasks: !0
|
|
145
|
+
},
|
|
55
146
|
// proof-like (no statement wrapping)
|
|
56
147
|
proof: { type: "proof", category: "proof-like", requiresStatement: !1 },
|
|
57
148
|
case: { type: "case", category: "proof-like", requiresStatement: !1 },
|
|
58
149
|
// solution-like (no statement wrapping)
|
|
59
|
-
solution: {
|
|
150
|
+
solution: {
|
|
151
|
+
type: "solution",
|
|
152
|
+
category: "solution-like",
|
|
153
|
+
requiresStatement: !1
|
|
154
|
+
},
|
|
60
155
|
hint: { type: "hint", category: "solution-like", requiresStatement: !1 },
|
|
61
|
-
answer: {
|
|
156
|
+
answer: {
|
|
157
|
+
type: "answer",
|
|
158
|
+
category: "solution-like",
|
|
159
|
+
requiresStatement: !1
|
|
160
|
+
}
|
|
62
161
|
}, _t = $;
|
|
63
162
|
function de(e) {
|
|
64
163
|
return $[e.toLowerCase()];
|
|
65
164
|
}
|
|
66
165
|
const Y = new Set(
|
|
67
|
-
Object.entries($).filter(
|
|
166
|
+
Object.entries($).filter(
|
|
167
|
+
([e, t]) => t.category === "proof-like" || t.category === "solution-like"
|
|
168
|
+
).map(([e]) => e)
|
|
68
169
|
);
|
|
69
170
|
function C(e, t, n) {
|
|
70
171
|
return {
|
|
@@ -135,9 +236,23 @@ function ge(e, t, n, o, i, r, s) {
|
|
|
135
236
|
m && l.push(m);
|
|
136
237
|
}
|
|
137
238
|
} else
|
|
138
|
-
j(
|
|
239
|
+
j(
|
|
240
|
+
l,
|
|
241
|
+
e,
|
|
242
|
+
o,
|
|
243
|
+
i,
|
|
244
|
+
r,
|
|
245
|
+
s
|
|
246
|
+
);
|
|
139
247
|
} else
|
|
140
|
-
j(
|
|
248
|
+
j(
|
|
249
|
+
l,
|
|
250
|
+
e,
|
|
251
|
+
o,
|
|
252
|
+
i,
|
|
253
|
+
r,
|
|
254
|
+
s
|
|
255
|
+
);
|
|
141
256
|
return C(e.type, l, t);
|
|
142
257
|
}
|
|
143
258
|
function j(e, t, n, o, i, r) {
|
|
@@ -624,8 +739,15 @@ function ze(e) {
|
|
|
624
739
|
for (let r = 0; r < t.length && t[r] === ":"; r++)
|
|
625
740
|
n++;
|
|
626
741
|
if (n < 3) return null;
|
|
627
|
-
const o = t.slice(n).trim(), i = o.match(
|
|
628
|
-
|
|
742
|
+
const o = t.slice(n).trim(), i = o.match(
|
|
743
|
+
/^([a-zA-Z0-9_-]+)(\[[^\]]*\])?(\{[^}]*\})?$/
|
|
744
|
+
);
|
|
745
|
+
return o === "" ? { colons: n, label: null, lineIndex: -1, isOpen: !1 } : i ? {
|
|
746
|
+
colons: n,
|
|
747
|
+
label: i[0],
|
|
748
|
+
lineIndex: -1,
|
|
749
|
+
isOpen: !0
|
|
750
|
+
} : null;
|
|
629
751
|
}
|
|
630
752
|
function We(e) {
|
|
631
753
|
const t = [], n = [];
|
|
@@ -828,7 +950,11 @@ function rt(e) {
|
|
|
828
950
|
const st = function(e) {
|
|
829
951
|
return function(n, o) {
|
|
830
952
|
if (typeof o?.value == "string") {
|
|
831
|
-
const i = rt(o.value), r = e?.documentRoot ?? i.documentRoot, s = e?.topLevelDivision ?? i.division ?? (r ? M(r) : "chapter"), l = e?.topLevelAttributes ?? i.attributes, c = e?.topLevelTitle ?? i.title, u = Ke(
|
|
953
|
+
const i = rt(o.value), r = e?.documentRoot ?? i.documentRoot, s = e?.topLevelDivision ?? i.division ?? (r ? M(r) : "chapter"), l = e?.topLevelAttributes ?? i.attributes, c = e?.topLevelTitle ?? i.title, u = Ke(
|
|
954
|
+
i.body
|
|
955
|
+
), a = He(u), p = _e(a), g = H().data("micromarkExtensions", [
|
|
956
|
+
{ disable: { null: ["codeIndented"] } }
|
|
957
|
+
]).use(X).use(Z).parse(p.markdown);
|
|
832
958
|
return Be(g, p.tokens), B(g, p.markdown, {
|
|
833
959
|
topLevelDivision: s,
|
|
834
960
|
documentRoot: r,
|
package/dist/lib/context.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - Factories apply spec-driven semantic rules uniformly
|
|
8
8
|
* - Adding new directives requires only configuration change, not new functions
|
|
9
9
|
*/
|
|
10
|
-
export type DirectiveCategory =
|
|
10
|
+
export type DirectiveCategory = "theorem-like" | "proof-like" | "definition-like" | "axiom-like" | "remark-like" | "example-like" | "project-like" | "exercise-like" | "solution-like";
|
|
11
11
|
/**
|
|
12
12
|
* Semantic specification for how a directive type should be converted.
|
|
13
13
|
* This pattern mirrors unified-latex-to-pretext's factory specifications.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Plugin } from 'unified';
|
|
2
2
|
import { Root, Text } from 'mdast';
|
|
3
3
|
export interface Math {
|
|
4
|
-
type:
|
|
4
|
+
type: "math";
|
|
5
5
|
value: string;
|
|
6
6
|
meta?: string;
|
|
7
7
|
}
|
|
8
|
-
declare module
|
|
8
|
+
declare module "mdast" {
|
|
9
9
|
interface PhrasingContentMap {
|
|
10
10
|
math: Math;
|
|
11
11
|
}
|
package/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require(
|
|
1
|
+
module.exports = require("./dist/index.cjs");
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./dist/index.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pretextbook/remark-pretext",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "remark plugin to transform markdown-style PreTeXt directives into ptxast",
|
|
5
5
|
"author": "Oscar Levin",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"test": "vitest run"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@pretextbook/ptxast": "^0.0
|
|
42
|
+
"@pretextbook/ptxast": "^0.1.0",
|
|
43
43
|
"@types/mdast": "^4.0.0",
|
|
44
44
|
"mdast-util-directive": "^3.0.0",
|
|
45
45
|
"remark-directive": "^4.0.0",
|