@notion-headless-cms/notion-katex 0.1.6 → 0.1.7
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.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type {\n BlockEnricher,\n NotionBlockTreeNode,\n} from \"@notion-headless-cms/notion-orm\";\nimport katex from \"katex\";\n\n/** `notionKatex()` のオプション。KaTeX の renderToString に渡すオプションのサブセット。 */\nexport interface NotionKatexOptions {\n /** 数式をブロック表示(display mode)にする。デフォルト: true。 */\n displayMode?: boolean;\n /** レンダリングエラーを throw する。false の場合はエラー時に __cachedHtml を設定しない。デフォルト: false。 */\n throwOnError?: boolean;\n /** KaTeX マクロ定義。 */\n macros?: Record<string, string>;\n}\n\n/** equation ブロックに `__cachedHtml` が付与された拡張型。 */\nexport type EquationBlockWithCachedHtml = {\n type: \"equation\";\n equation: { expression: string; __cachedHtml: string };\n};\n\n/**\n * fetch 時に Notion の equation ブロックを KaTeX で HTML 化し、\n * `block.equation.__cachedHtml` に埋め込む `BlockEnricher` を返す。\n *\n * `react-renderer` の Equation スタブは `__cachedHtml` があれば\n * `dangerouslySetInnerHTML` で描画するため、Workers バンドルから katex を除外できる。\n *\n * @example\n * ```ts\n * import { notionKatex } from \"@notion-headless-cms/notion-katex\";\n * import { createNotionCollection } from \"@notion-headless-cms/notion-orm\";\n *\n * source: createNotionCollection({\n * token: process.env.NOTION_TOKEN,\n * dataSourceId: \"...\",\n * enrichers: [notionKatex({ displayMode: true })],\n * });\n * ```\n */\nexport function notionKatex(opts?: NotionKatexOptions): BlockEnricher {\n const katexOpts = {\n displayMode: opts?.displayMode ?? true,\n throwOnError: opts?.throwOnError ?? false,\n ...(opts?.macros && { macros: opts.macros }),\n };\n\n return async (\n blocks: NotionBlockTreeNode[],\n ): Promise<NotionBlockTreeNode[]> => {\n enrichBlocks(blocks, katexOpts);\n return blocks;\n };\n}\n\ntype KatexRenderOptions = {\n displayMode: boolean;\n throwOnError: boolean;\n macros?: Record<string, string>;\n};\n\nfunction enrichBlocks(\n blocks: NotionBlockTreeNode[],\n opts: KatexRenderOptions,\n): void {\n for (const block of blocks) {\n if (block.type === \"equation\") {\n const eq = block.equation as {\n expression: string;\n __cachedHtml?: string;\n };\n try {\n eq.__cachedHtml = katex.renderToString(eq.expression, opts);\n } catch {\n // レンダリング失敗時は __cachedHtml を設定せず、react-renderer の <pre> フォールバックを使う\n }\n }\n if (block.children?.length) {\n enrichBlocks(block.children, opts);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,YAAY,MAA0C;CACpE,MAAM,YAAY;EAChB,aAAa,MAAM,eAAe;EAClC,cAAc,MAAM,gBAAgB;EACpC,GAAI,MAAM,UAAU,EAAE,QAAQ,KAAK,
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type {\n BlockEnricher,\n NotionBlockTreeNode,\n} from \"@notion-headless-cms/notion-orm\";\nimport katex from \"katex\";\n\n/** `notionKatex()` のオプション。KaTeX の renderToString に渡すオプションのサブセット。 */\nexport interface NotionKatexOptions {\n /** 数式をブロック表示(display mode)にする。デフォルト: true。 */\n displayMode?: boolean;\n /** レンダリングエラーを throw する。false の場合はエラー時に __cachedHtml を設定しない。デフォルト: false。 */\n throwOnError?: boolean;\n /** KaTeX マクロ定義。 */\n macros?: Record<string, string>;\n}\n\n/** equation ブロックに `__cachedHtml` が付与された拡張型。 */\nexport type EquationBlockWithCachedHtml = {\n type: \"equation\";\n equation: { expression: string; __cachedHtml: string };\n};\n\n/**\n * fetch 時に Notion の equation ブロックを KaTeX で HTML 化し、\n * `block.equation.__cachedHtml` に埋め込む `BlockEnricher` を返す。\n *\n * `react-renderer` の Equation スタブは `__cachedHtml` があれば\n * `dangerouslySetInnerHTML` で描画するため、Workers バンドルから katex を除外できる。\n *\n * @example\n * ```ts\n * import { notionKatex } from \"@notion-headless-cms/notion-katex\";\n * import { createNotionCollection } from \"@notion-headless-cms/notion-orm\";\n *\n * source: createNotionCollection({\n * token: process.env.NOTION_TOKEN,\n * dataSourceId: \"...\",\n * enrichers: [notionKatex({ displayMode: true })],\n * });\n * ```\n */\nexport function notionKatex(opts?: NotionKatexOptions): BlockEnricher {\n const katexOpts = {\n displayMode: opts?.displayMode ?? true,\n throwOnError: opts?.throwOnError ?? false,\n ...(opts?.macros && { macros: opts.macros }),\n };\n\n return async (\n blocks: NotionBlockTreeNode[],\n ): Promise<NotionBlockTreeNode[]> => {\n enrichBlocks(blocks, katexOpts);\n return blocks;\n };\n}\n\ntype KatexRenderOptions = {\n displayMode: boolean;\n throwOnError: boolean;\n macros?: Record<string, string>;\n};\n\nfunction enrichBlocks(\n blocks: NotionBlockTreeNode[],\n opts: KatexRenderOptions,\n): void {\n for (const block of blocks) {\n if (block.type === \"equation\") {\n const eq = block.equation as {\n expression: string;\n __cachedHtml?: string;\n };\n try {\n eq.__cachedHtml = katex.renderToString(eq.expression, opts);\n } catch {\n // レンダリング失敗時は __cachedHtml を設定せず、react-renderer の <pre> フォールバックを使う\n }\n }\n if (block.children?.length) {\n enrichBlocks(block.children, opts);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,YAAY,MAA0C;CACpE,MAAM,YAAY;EAChB,aAAa,MAAM,eAAe;EAClC,cAAc,MAAM,gBAAgB;EACpC,GAAI,MAAM,UAAU,EAAE,QAAQ,KAAK,OAAO;CAC5C;CAEA,OAAO,OACL,WACmC;EACnC,aAAa,QAAQ,SAAS;EAC9B,OAAO;CACT;AACF;AAQA,SAAS,aACP,QACA,MACM;CACN,KAAK,MAAM,SAAS,QAAQ;EAC1B,IAAI,MAAM,SAAS,YAAY;GAC7B,MAAM,KAAK,MAAM;GAIjB,IAAI;IACF,GAAG,eAAe,MAAM,eAAe,GAAG,YAAY,IAAI;GAC5D,QAAQ,CAER;EACF;EACA,IAAI,MAAM,UAAU,QAClB,aAAa,MAAM,UAAU,IAAI;CAErC;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.7",
|
|
4
4
|
"description": "Notion equation ブロックを fetch 時に KaTeX で pre-render し、Workers バンドルから katex を除外する拡張パッケージ",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"notion",
|
|
@@ -41,11 +41,11 @@
|
|
|
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.29"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"katex": "^0.16.
|
|
48
|
-
"@notion-headless-cms/notion-orm": "0.1.
|
|
47
|
+
"katex": "^0.16.46",
|
|
48
|
+
"@notion-headless-cms/notion-orm": "0.1.29"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "tsdown src/index.ts --format esm --dts --sourcemap --out-dir dist",
|