@pretextbook/remark-pretext 0.0.1
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 +76 -0
- package/index.cjs +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# @pretextbook/remark-pretext
|
|
2
|
+
|
|
3
|
+
A [remark](https://github.com/remarkjs/remark) plugin that transforms **markdown-style PreTeXt** into a [`@pretextbook/ptxast`](../ptxast) tree.
|
|
4
|
+
|
|
5
|
+
## What is markdown-style PreTeXt?
|
|
6
|
+
|
|
7
|
+
Standard Markdown extended with [generic directives](https://github.com/remarkjs/remark-directive) to express PreTeXt-specific environments:
|
|
8
|
+
|
|
9
|
+
```markdown
|
|
10
|
+
## Pythagorean Theorem
|
|
11
|
+
|
|
12
|
+
A paragraph with inline $math$ and **important** terms.
|
|
13
|
+
|
|
14
|
+
::::theorem[Pythagorean Theorem]{#thm-pythagoras}
|
|
15
|
+
For a right triangle with legs $a$, $b$ and hypotenuse $c$:
|
|
16
|
+
|
|
17
|
+
$$
|
|
18
|
+
a^2 + b^2 = c^2
|
|
19
|
+
$$
|
|
20
|
+
|
|
21
|
+
:::proof
|
|
22
|
+
Left as an exercise.
|
|
23
|
+
:::
|
|
24
|
+
::::
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
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'
|
|
34
|
+
|
|
35
|
+
const processor = unified()
|
|
36
|
+
.use(remarkParse)
|
|
37
|
+
.use(remarkDirective) // enables ::: directives
|
|
38
|
+
.use(remarkPretext)
|
|
39
|
+
|
|
40
|
+
const mdast = processor.parse(markdownString)
|
|
41
|
+
const ptxast = processor.runSync(mdast, { value: markdownString }) // PtxRoot
|
|
42
|
+
|
|
43
|
+
// Serialize to XML (use @pretextbook/ptxast-util-to-xml)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
> **Note:** Use `.runSync()` (or `.run()`) rather than `.parse()` — `.parse()` only runs the parser phase; transformers (including `remarkPretext`) run during the transform phase.
|
|
47
|
+
|
|
48
|
+
## Syntax Rules
|
|
49
|
+
|
|
50
|
+
- `:::name[optional title]{#id attr=val}` opens a block directive
|
|
51
|
+
- `:::` alone closes it
|
|
52
|
+
- **Nesting**: use one more colon for the outer container when nesting directives:
|
|
53
|
+
- `::::theorem` containing `:::proof` — use `::::` for theorem, `:::` for proof
|
|
54
|
+
- All standard PreTeXt block names are recognised (see `DIRECTIVE_MAP`)
|
|
55
|
+
- Standard Markdown headings map to divisions:
|
|
56
|
+
- `#` → `<chapter>`
|
|
57
|
+
- `##` → `<section>`
|
|
58
|
+
- `###` → `<subsection>`
|
|
59
|
+
- `####` → `<subsubsection>`
|
|
60
|
+
- Inline elements:
|
|
61
|
+
- `*text*` → `<em>`
|
|
62
|
+
- `**text**` → `<alert>` (semantic emphasis in PreTeXt)
|
|
63
|
+
- `` `code` `` → `<c>`
|
|
64
|
+
- `$...$` and `\(...\)` → `<m>`
|
|
65
|
+
- `$$...$$` and `\[...\]` → display math (`<md>`)
|
|
66
|
+
|
|
67
|
+
## Supported Directives
|
|
68
|
+
|
|
69
|
+
| Category | Names |
|
|
70
|
+
|----------|-------|
|
|
71
|
+
| theorem-like | `theorem`, `lemma`, `corollary`, `proposition`, `claim`, `fact`, `conjecture`, `axiom`, `principle`, `hypothesis`, `algorithm` |
|
|
72
|
+
| definition-like | `definition`, `notation` |
|
|
73
|
+
| remark-like | `remark`, `note`, `observation`, `warning`, `insight`, `assemblage` |
|
|
74
|
+
| example-like | `example`, `question`, `problem`, `exercise`, `activity`, `exploration`, `investigation`, `project` |
|
|
75
|
+
| proof-like | `proof`, `case` |
|
|
76
|
+
| solution-like | `solution`, `hint`, `answer` |
|
package/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../../dist/packages/remark-pretext/index.cjs');
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/packages/remark-pretext/index.d.ts';
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/packages/remark-pretext/index.js';
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pretextbook/remark-pretext",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "remark plugin to transform markdown-style PreTeXt directives into ptxast",
|
|
5
|
+
"author": "Oscar Levin",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/pretextbook/pretext-tools.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/pretextbook/pretext-tools/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/pretextbook/pretext-tools/packages/remark-pretext#readme",
|
|
15
|
+
"private": false,
|
|
16
|
+
"type": "module",
|
|
17
|
+
"main": "./index.cjs",
|
|
18
|
+
"module": "./index.js",
|
|
19
|
+
"types": "./index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./index.d.ts",
|
|
23
|
+
"import": "./index.js",
|
|
24
|
+
"require": "./index.cjs",
|
|
25
|
+
"default": "./index.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"files": [
|
|
30
|
+
"*.js",
|
|
31
|
+
"*.cjs",
|
|
32
|
+
"*.d.ts",
|
|
33
|
+
"*.d.cts",
|
|
34
|
+
"lib",
|
|
35
|
+
"types"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "vite build",
|
|
39
|
+
"test": "vitest run"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@pretextbook/ptxast": "^0.0.1",
|
|
43
|
+
"@types/mdast": "^4.0.0",
|
|
44
|
+
"mdast-util-directive": "^3.0.0",
|
|
45
|
+
"remark-directive": "^4.0.0",
|
|
46
|
+
"remark-parse": "^11.0.0",
|
|
47
|
+
"unified": "^11.0.0",
|
|
48
|
+
"unist-util-visit": "^5.0.0"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
}
|
|
53
|
+
}
|