@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 CHANGED
@@ -27,18 +27,18 @@ Left as an exercise.
27
27
  ## Usage
28
28
 
29
29
  ```ts
30
- import { unified } from 'unified'
31
- import remarkParse from 'remark-parse'
32
- import remarkDirective from 'remark-directive'
33
- import { remarkPretext } from '@pretextbook/remark-pretext'
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) // enables ::: directives
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 '@pretextbook/remark-pretext'
83
+ import { markdownToPretext } from "@pretextbook/remark-pretext";
84
84
 
85
- markdownToPretext('# Title\n\n## Sub', { topLevelDivision: 'section' })
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 | 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` |
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: { type: "theorem", category: "theorem-like", requiresStatement: !0 },
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: { type: "corollary", category: "theorem-like", requiresStatement: !0 },
26
- proposition: { type: "proposition", category: "theorem-like", requiresStatement: !0 },
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: { type: "conjecture", category: "theorem-like", requiresStatement: !0 },
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: { type: "principle", category: "theorem-like", requiresStatement: !0 },
32
- hypothesis: { type: "hypothesis", category: "theorem-like", requiresStatement: !0 },
33
- algorithm: { type: "algorithm", category: "theorem-like", requiresStatement: !0 },
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: { type: "definition", category: "definition-like", requiresStatement: !0 },
36
- notation: { type: "notation", category: "definition-like", requiresStatement: !0 },
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: { type: "observation", category: "remark-like", requiresStatement: !1 },
41
- warning: { type: "warning", category: "remark-like", requiresStatement: !1 },
42
- insight: { type: "insight", category: "remark-like", requiresStatement: !1 },
43
- assemblage: { type: "assemblage", category: "remark-like", requiresStatement: !1 },
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: { type: "example", category: "example-like", requiresStatement: !1 },
46
- question: { type: "question", category: "example-like", requiresStatement: !1 },
47
- problem: { type: "problem", category: "example-like", requiresStatement: !1 },
48
- exercise: { type: "exercise", category: "example-like", requiresStatement: !0, hasNestedTasks: !0 },
49
- activity: { type: "activity", category: "example-like", requiresStatement: !1 },
50
- exploration: { type: "exploration", category: "example-like", requiresStatement: !1 },
51
- investigation: { type: "investigation", category: "example-like", requiresStatement: !1 },
52
- project: { type: "project", category: "example-like", requiresStatement: !0, hasNestedTasks: !0 },
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: { type: "task", category: "example-like", requiresStatement: !0, hasNestedTasks: !0 },
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: { type: "solution", category: "solution-like", requiresStatement: !1 },
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: { type: "answer", category: "solution-like", requiresStatement: !1 }
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(([e, t]) => t.category === "proof-like" || t.category === "solution-like").map(([e]) => e)
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(l, e, o, i, r, s);
239
+ j(
240
+ l,
241
+ e,
242
+ o,
243
+ i,
244
+ r,
245
+ s
246
+ );
139
247
  } else
140
- j(l, e, o, i, r, s);
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(/^([a-zA-Z0-9_-]+)(\[[^\]]*\])?(\{[^}]*\})?$/);
628
- return o === "" ? { colons: n, label: null, lineIndex: -1, isOpen: !1 } : i ? { colons: n, label: i[0], lineIndex: -1, isOpen: !0 } : null;
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(i.body), a = He(u), p = _e(a), g = H().data("micromarkExtensions", [{ disable: { null: ["codeIndented"] } }]).use(X).use(Z).parse(p.markdown);
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,
@@ -37,7 +37,7 @@ export interface VisitContext {
37
37
  headingDepthOffset?: number;
38
38
  }
39
39
  export interface ConversionMessage {
40
- type: 'warning' | 'error';
40
+ type: "warning" | "error";
41
41
  reason: string;
42
42
  category: string;
43
43
  position?: {
@@ -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 = 'theorem-like' | 'proof-like' | 'definition-like' | 'axiom-like' | 'remark-like' | 'example-like' | 'project-like' | 'exercise-like' | 'solution-like';
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: 'math';
4
+ type: "math";
5
5
  value: string;
6
6
  meta?: string;
7
7
  }
8
- declare module 'mdast' {
8
+ declare module "mdast" {
9
9
  interface PhrasingContentMap {
10
10
  math: Math;
11
11
  }
package/index.cjs CHANGED
@@ -1 +1 @@
1
- module.exports = require('./dist/index.cjs');
1
+ module.exports = require("./dist/index.cjs");
package/index.js CHANGED
@@ -1 +1 @@
1
- export * from './dist/index.js';
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.11",
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.8",
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",