@matra/markdown-unified 0.1.0 → 0.1.2
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 +50 -5
- package/package.json +3 -3
- package/src/index.mjs +18 -2
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# @matra/markdown-unified
|
|
2
2
|
|
|
3
|
-
The official, optional Markdown preset for `@matra/site-generation` **0.2.x**
|
|
3
|
+
The official, optional Markdown preset for `@matra/site-generation` **0.2.x** and **0.3.x**.
|
|
4
4
|
Install the preset **in the site project**, not in the language core or globally alongside the CLI:
|
|
5
5
|
|
|
6
6
|
```sh
|
|
7
|
-
npm install @matra/markdown-unified@^0.1.
|
|
7
|
+
npm install @matra/markdown-unified@^0.1.2
|
|
8
8
|
```
|
|
9
9
|
|
|
10
10
|
The global CLI provides the generator: installing this preset alone does not install a second copy.
|
|
11
|
-
For the JavaScript API, also install `@matra/site-generation@^0.
|
|
11
|
+
For the JavaScript API, also install `@matra/site-generation@^0.3.0` locally.
|
|
12
12
|
In a file-based site, set `site.markdown: unified`. In JavaScript, pass `markdown: "unified"` to
|
|
13
13
|
`generateSite()`, or use the factory to add trusted plugins:
|
|
14
14
|
|
|
@@ -40,6 +40,49 @@ executed. Plugins are trusted build-time JavaScript, not a way to turn on arbitr
|
|
|
40
40
|
Pass unified plugin lists as `remarkPlugins` (Markdown tree) or `rehypePlugins` (HTML tree).
|
|
41
41
|
The VFile has the logical article path and `file.data.metadata`. Plugin diagnostics fail the build.
|
|
42
42
|
|
|
43
|
+
## KaTeX strictness
|
|
44
|
+
|
|
45
|
+
The JavaScript factory accepts KaTeX's `strict` setting as `katexStrict`:
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
const markdown = createUnifiedMarkdown({ katexStrict: "ignore" })
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
It accepts `true`, `false`, `"error"`, `"warn"`, `"ignore"`, or a KaTeX strict callback.
|
|
52
|
+
The default is KaTeX's default (`"warn"`), including warnings for some Unicode text and array
|
|
53
|
+
constructs. `"ignore"` suppresses these strictness warnings, not invalid TeX errors; use a callback
|
|
54
|
+
to allow selected cases instead. Math remains MathML and `trust` remains `false`. Other KaTeX
|
|
55
|
+
options are not exposed. This option and plugins require the JavaScript factory with `generateSite`;
|
|
56
|
+
`site.markdown: unified` uses the defaults.
|
|
57
|
+
|
|
58
|
+
## Migrating legacy HTML and embeds
|
|
59
|
+
|
|
60
|
+
Raw HTML remains escaped by default, even in otherwise trusted articles. To migrate a known legacy
|
|
61
|
+
block, explicitly map the exact block to a fixed node in a trusted plugin. Unrecognized HTML remains
|
|
62
|
+
text; this example does not parse or pass through arbitrary HTML:
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
function legacyNotice() {
|
|
66
|
+
const approved = '<div class="legacy-note">Archived notice</div>'
|
|
67
|
+
return tree => {
|
|
68
|
+
tree.children = tree.children.map(node => {
|
|
69
|
+
if (node.type !== "text" || node.value.trim() !== approved) return node
|
|
70
|
+
return {
|
|
71
|
+
type: "element", tagName: "aside", position: node.position,
|
|
72
|
+
properties: { className: ["legacy-note"] },
|
|
73
|
+
children: [{ type: "text", value: "Archived notice" }],
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const markdown = createUnifiedMarkdown({ rehypePlugins: [legacyNotice] })
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
This only matches that standalone block, not inline fragments or arbitrary attributes. Maintain an
|
|
83
|
+
explicit allowlist for each legacy form; do not copy article-provided HTML, attributes, scripts,
|
|
84
|
+
event handlers or URLs into executable nodes. Plugins execute with the build's privileges.
|
|
85
|
+
|
|
43
86
|
For example, a site can allow **one specific embed** by replacing a standalone link in a rehype plugin:
|
|
44
87
|
|
|
45
88
|
```js
|
|
@@ -62,5 +105,7 @@ const markdown = createUnifiedMarkdown({ rehypePlugins: [featuredDemo] })
|
|
|
62
105
|
```
|
|
63
106
|
|
|
64
107
|
Keep original node positions when replacing links or images. Matra resolves their URLs after **all**
|
|
65
|
-
plugins and reports the original filename and line.
|
|
66
|
-
|
|
108
|
+
plugins and reports the original filename and line. External URLs are not fetched or checked for
|
|
109
|
+
safety. Embeds can load third-party content; choose a trusted origin, an appropriate sandbox and
|
|
110
|
+
content-security policy for the site. Legacy cards, embeds, ads and analytics remain site-specific.
|
|
111
|
+
See the [site contract](../../spec/site-generation.md) / [日本語](../../spec/site-generation.ja.md).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matra/markdown-unified",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Official unified Markdown preset for Matra site generation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./src/index.mjs",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"vfile": "^6.0.3"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@matra/site-generation": "^0.
|
|
23
|
+
"@matra/site-generation": "^0.3.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@matra/site-generation": "^0.2.0"
|
|
26
|
+
"@matra/site-generation": "^0.2.0 || ^0.3.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependenciesMeta": {
|
|
29
29
|
"@matra/site-generation": {
|
package/src/index.mjs
CHANGED
|
@@ -96,7 +96,19 @@ function toNodes(children, schema = html) {
|
|
|
96
96
|
})
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
export function createUnifiedMarkdown({
|
|
99
|
+
export function createUnifiedMarkdown({
|
|
100
|
+
remarkPlugins = [],
|
|
101
|
+
rehypePlugins = [],
|
|
102
|
+
katexStrict,
|
|
103
|
+
} = {}) {
|
|
104
|
+
if (
|
|
105
|
+
katexStrict !== undefined &&
|
|
106
|
+
typeof katexStrict !== "boolean" &&
|
|
107
|
+
typeof katexStrict !== "function" &&
|
|
108
|
+
!["ignore", "warn", "error"].includes(katexStrict)
|
|
109
|
+
) {
|
|
110
|
+
throw new TypeError('katexStrict must be a boolean, "ignore", "warn", "error", or a function')
|
|
111
|
+
}
|
|
100
112
|
const processor = unified()
|
|
101
113
|
.use(remarkParse)
|
|
102
114
|
.use(remarkGfm)
|
|
@@ -108,7 +120,11 @@ export function createUnifiedMarkdown({ remarkPlugins = [], rehypePlugins = [] }
|
|
|
108
120
|
html: (_state, node) => ({ type: "text", value: node.value, position: node.position }),
|
|
109
121
|
},
|
|
110
122
|
})
|
|
111
|
-
.use(rehypeKatex, {
|
|
123
|
+
.use(rehypeKatex, {
|
|
124
|
+
output: "mathml",
|
|
125
|
+
trust: false,
|
|
126
|
+
...(katexStrict === undefined ? {} : { strict: katexStrict }),
|
|
127
|
+
})
|
|
112
128
|
.use(rehypePlugins)
|
|
113
129
|
.freeze()
|
|
114
130
|
return async ({ body, document, metadata }) => {
|