@notion-headless-cms/notion-katex 0.1.7 → 0.1.9
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/dist/index.d.mts +9 -22
- package/dist/index.mjs +9 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,43 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ContentExtension } from "@notion-headless-cms/notion-orm";
|
|
2
2
|
|
|
3
3
|
//#region src/index.d.ts
|
|
4
4
|
/** `notionKatex()` のオプション。KaTeX の renderToString に渡すオプションのサブセット。 */
|
|
5
5
|
interface NotionKatexOptions {
|
|
6
6
|
/** 数式をブロック表示(display mode)にする。デフォルト: true。 */
|
|
7
7
|
displayMode?: boolean;
|
|
8
|
-
/** レンダリングエラーを throw する。false
|
|
8
|
+
/** レンダリングエラーを throw する。false の場合はエラー時に数式をそのまま表示する。デフォルト: false。 */
|
|
9
9
|
throwOnError?: boolean;
|
|
10
10
|
/** KaTeX マクロ定義。 */
|
|
11
11
|
macros?: Record<string, string>;
|
|
12
12
|
}
|
|
13
|
-
/** equation ブロックに `__cachedHtml` が付与された拡張型。 */
|
|
14
|
-
type EquationBlockWithCachedHtml = {
|
|
15
|
-
type: "equation";
|
|
16
|
-
equation: {
|
|
17
|
-
expression: string;
|
|
18
|
-
__cachedHtml: string;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
13
|
/**
|
|
22
|
-
*
|
|
23
|
-
* `block.equation.__cachedHtml` に埋め込む `BlockEnricher` を返す。
|
|
14
|
+
* Notion の equation ブロック・インライン数式を KaTeX で描画する `ContentExtension` を返す。
|
|
24
15
|
*
|
|
25
|
-
* `
|
|
26
|
-
* `
|
|
16
|
+
* markdown 戦略: `rehype-katex` を unified パイプラインへ注入する。
|
|
17
|
+
* `remarkMath` はパイプラインに既存のため `rehypePlugins` のみ追加。
|
|
27
18
|
*
|
|
28
19
|
* @example
|
|
29
20
|
* ```ts
|
|
30
21
|
* import { notionKatex } from "@notion-headless-cms/notion-katex";
|
|
31
|
-
* import { createNotionCollection } from "@notion-headless-cms/notion-orm";
|
|
32
22
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* dataSourceId: "...",
|
|
36
|
-
* enrichers: [notionKatex({ displayMode: true })],
|
|
37
|
-
* });
|
|
23
|
+
* // markdown 戦略
|
|
24
|
+
* <Renderer content={item.content} extensions={[notionKatex()]} />
|
|
38
25
|
* ```
|
|
39
26
|
*/
|
|
40
|
-
declare function notionKatex(opts?: NotionKatexOptions):
|
|
27
|
+
declare function notionKatex(opts?: NotionKatexOptions): ContentExtension;
|
|
41
28
|
//#endregion
|
|
42
|
-
export {
|
|
29
|
+
export { NotionKatexOptions, notionKatex };
|
|
43
30
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import rehypeKatex from "rehype-katex";
|
|
2
2
|
//#region src/index.ts
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* `block.equation.__cachedHtml` に埋め込む `BlockEnricher` を返す。
|
|
4
|
+
* Notion の equation ブロック・インライン数式を KaTeX で描画する `ContentExtension` を返す。
|
|
6
5
|
*
|
|
7
|
-
* `
|
|
8
|
-
* `
|
|
6
|
+
* markdown 戦略: `rehype-katex` を unified パイプラインへ注入する。
|
|
7
|
+
* `remarkMath` はパイプラインに既存のため `rehypePlugins` のみ追加。
|
|
9
8
|
*
|
|
10
9
|
* @example
|
|
11
10
|
* ```ts
|
|
12
11
|
* import { notionKatex } from "@notion-headless-cms/notion-katex";
|
|
13
|
-
* import { createNotionCollection } from "@notion-headless-cms/notion-orm";
|
|
14
12
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* dataSourceId: "...",
|
|
18
|
-
* enrichers: [notionKatex({ displayMode: true })],
|
|
19
|
-
* });
|
|
13
|
+
* // markdown 戦略
|
|
14
|
+
* <Renderer content={item.content} extensions={[notionKatex()]} />
|
|
20
15
|
* ```
|
|
21
16
|
*/
|
|
22
17
|
function notionKatex(opts) {
|
|
@@ -25,21 +20,9 @@ function notionKatex(opts) {
|
|
|
25
20
|
throwOnError: opts?.throwOnError ?? false,
|
|
26
21
|
...opts?.macros && { macros: opts.macros }
|
|
27
22
|
};
|
|
28
|
-
return
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
function enrichBlocks(blocks, opts) {
|
|
34
|
-
for (const block of blocks) {
|
|
35
|
-
if (block.type === "equation") {
|
|
36
|
-
const eq = block.equation;
|
|
37
|
-
try {
|
|
38
|
-
eq.__cachedHtml = katex.renderToString(eq.expression, opts);
|
|
39
|
-
} catch {}
|
|
40
|
-
}
|
|
41
|
-
if (block.children?.length) enrichBlocks(block.children, opts);
|
|
42
|
-
}
|
|
23
|
+
return { getMarkdownPlugins() {
|
|
24
|
+
return { rehypePlugins: [[rehypeKatex, katexOpts]] };
|
|
25
|
+
} };
|
|
43
26
|
}
|
|
44
27
|
//#endregion
|
|
45
28
|
export { notionKatex };
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { ContentExtension } from \"@notion-headless-cms/notion-orm\";\nimport rehypeKatex from \"rehype-katex\";\n\n/** `notionKatex()` のオプション。KaTeX の renderToString に渡すオプションのサブセット。 */\nexport interface NotionKatexOptions {\n /** 数式をブロック表示(display mode)にする。デフォルト: true。 */\n displayMode?: boolean;\n /** レンダリングエラーを throw する。false の場合はエラー時に数式をそのまま表示する。デフォルト: false。 */\n throwOnError?: boolean;\n /** KaTeX マクロ定義。 */\n macros?: Record<string, string>;\n}\n\n/**\n * Notion の equation ブロック・インライン数式を KaTeX で描画する `ContentExtension` を返す。\n *\n * markdown 戦略: `rehype-katex` を unified パイプラインへ注入する。\n * `remarkMath` はパイプラインに既存のため `rehypePlugins` のみ追加。\n *\n * @example\n * ```ts\n * import { notionKatex } from \"@notion-headless-cms/notion-katex\";\n *\n * // markdown 戦略\n * <Renderer content={item.content} extensions={[notionKatex()]} />\n * ```\n */\nexport function notionKatex(opts?: NotionKatexOptions): ContentExtension {\n const katexOpts = {\n displayMode: opts?.displayMode ?? true,\n throwOnError: opts?.throwOnError ?? false,\n ...(opts?.macros && { macros: opts.macros }),\n };\n return {\n getMarkdownPlugins() {\n return { rehypePlugins: [[rehypeKatex, katexOpts]] };\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA2BA,SAAgB,YAAY,MAA6C;CACvE,MAAM,YAAY;EAChB,aAAa,MAAM,eAAe;EAClC,cAAc,MAAM,gBAAgB;EACpC,GAAI,MAAM,UAAU,EAAE,QAAQ,KAAK,OAAO;CAC5C;CACA,OAAO,EACL,qBAAqB;EACnB,OAAO,EAAE,eAAe,CAAC,CAAC,aAAa,SAAS,CAAC,EAAE;CACrD,EACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@notion-headless-cms/notion-katex",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "Notion equation ブロックを fetch 時に KaTeX で pre-render し、Workers バンドルから katex を除外する拡張パッケージ",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"notion",
|
|
@@ -41,11 +41,14 @@
|
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"katex": "^0.16.11",
|
|
44
|
-
"@notion-headless-cms/notion-orm": "0.1.
|
|
44
|
+
"@notion-headless-cms/notion-orm": "0.1.31"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"katex": "^0.16.
|
|
48
|
-
"@notion-headless-cms/notion-orm": "0.1.
|
|
47
|
+
"katex": "^0.16.47",
|
|
48
|
+
"@notion-headless-cms/notion-orm": "0.1.31"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"rehype-katex": "^7.0.1"
|
|
49
52
|
},
|
|
50
53
|
"scripts": {
|
|
51
54
|
"build": "tsdown src/index.ts --format esm --dts --sourcemap --out-dir dist",
|