@atikk-co-jp/notion-mcp-server 0.2.3 → 0.4.0
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.ja.md +105 -4
- package/README.md +105 -4
- package/dist/src/converters/__tests__/markdown-to-blocks.test.d.ts +2 -0
- package/dist/src/converters/__tests__/markdown-to-blocks.test.d.ts.map +1 -0
- package/dist/src/converters/__tests__/markdown-to-blocks.test.js +245 -0
- package/dist/src/converters/index.d.ts +1 -0
- package/dist/src/converters/index.d.ts.map +1 -1
- package/dist/src/converters/index.js +2 -0
- package/dist/src/converters/markdown-to-blocks.d.ts +21 -0
- package/dist/src/converters/markdown-to-blocks.d.ts.map +1 -0
- package/dist/src/converters/markdown-to-blocks.js +244 -0
- package/dist/src/notion-client.d.ts +40 -0
- package/dist/src/notion-client.d.ts.map +1 -1
- package/dist/src/notion-client.js +39 -0
- package/dist/src/tools/append-blocks-simple.d.ts +4 -0
- package/dist/src/tools/append-blocks-simple.d.ts.map +1 -0
- package/dist/src/tools/append-blocks-simple.js +36 -0
- package/dist/src/tools/create-database.d.ts.map +1 -1
- package/dist/src/tools/create-database.js +3 -1
- package/dist/src/tools/create-page-simple.d.ts +4 -0
- package/dist/src/tools/create-page-simple.d.ts.map +1 -0
- package/dist/src/tools/create-page-simple.js +54 -0
- package/dist/src/tools/delete-block.d.ts +4 -0
- package/dist/src/tools/delete-block.d.ts.map +1 -0
- package/dist/src/tools/delete-block.js +20 -0
- package/dist/src/tools/index.d.ts +14 -1
- package/dist/src/tools/index.d.ts.map +1 -1
- package/dist/src/tools/index.js +28 -1
- package/dist/src/tools/list-comments.d.ts +4 -0
- package/dist/src/tools/list-comments.d.ts.map +1 -0
- package/dist/src/tools/list-comments.js +50 -0
- package/dist/src/tools/list-users.d.ts +4 -0
- package/dist/src/tools/list-users.d.ts.map +1 -0
- package/dist/src/tools/list-users.js +31 -0
- package/dist/src/tools/move-page.d.ts +4 -0
- package/dist/src/tools/move-page.d.ts.map +1 -0
- package/dist/src/tools/move-page.js +43 -0
- package/dist/src/tools/query-database.d.ts.map +1 -1
- package/dist/src/tools/retrieve-block.d.ts +4 -0
- package/dist/src/tools/retrieve-block.d.ts.map +1 -0
- package/dist/src/tools/retrieve-block.js +32 -0
- package/dist/src/tools/retrieve-bot-user.d.ts +4 -0
- package/dist/src/tools/retrieve-bot-user.d.ts.map +1 -0
- package/dist/src/tools/retrieve-bot-user.js +16 -0
- package/dist/src/tools/retrieve-database.d.ts +4 -0
- package/dist/src/tools/retrieve-database.d.ts.map +1 -0
- package/dist/src/tools/retrieve-database.js +58 -0
- package/dist/src/tools/retrieve-page-property.d.ts +4 -0
- package/dist/src/tools/retrieve-page-property.d.ts.map +1 -0
- package/dist/src/tools/retrieve-page-property.js +33 -0
- package/dist/src/tools/retrieve-user.d.ts +4 -0
- package/dist/src/tools/retrieve-user.d.ts.map +1 -0
- package/dist/src/tools/retrieve-user.js +19 -0
- package/dist/src/tools/update-block-simple.d.ts +4 -0
- package/dist/src/tools/update-block-simple.d.ts.map +1 -0
- package/dist/src/tools/update-block-simple.js +68 -0
- package/dist/src/tools/update-block.d.ts +4 -0
- package/dist/src/tools/update-block.d.ts.map +1 -0
- package/dist/src/tools/update-block.js +30 -0
- package/package.json +1 -1
package/README.ja.md
CHANGED
|
@@ -8,12 +8,50 @@ Notion API用のMCP(Model Context Protocol)サーバー。AIアシスタン
|
|
|
8
8
|
|
|
9
9
|
## 特徴
|
|
10
10
|
|
|
11
|
-
- **ページ操作**: Notion
|
|
12
|
-
- **データベース操作**:
|
|
13
|
-
- **ブロック操作**:
|
|
11
|
+
- **ページ操作**: Notionページの作成、取得、更新、移動
|
|
12
|
+
- **データベース操作**: データベースの作成、取得、更新、フィルター/ソートを使ったクエリ
|
|
13
|
+
- **ブロック操作**: ブロックの取得、更新、削除、子要素の追加
|
|
14
14
|
- **検索**: ページとデータベースの横断検索
|
|
15
|
-
- **コメント**:
|
|
15
|
+
- **コメント**: コメントの作成・一覧取得
|
|
16
|
+
- **ユーザー**: ユーザー一覧取得、ユーザー情報取得
|
|
16
17
|
- **トークン効率化**: マークダウン/シンプル形式でトークン使用量を約96%削減
|
|
18
|
+
- **Markdown入力対応**: Markdownでコンテンツを作成・追加(入力トークン80%削減)
|
|
19
|
+
|
|
20
|
+
## API対応表
|
|
21
|
+
|
|
22
|
+
| カテゴリ | Notion API | MCPツール | 形式 |
|
|
23
|
+
|---------|-----------|----------|------|
|
|
24
|
+
| **ページ** | | | |
|
|
25
|
+
| | [Create page](https://developers.notion.com/reference/post-page) | `create-page` | JSON |
|
|
26
|
+
| | | `create-page-simple` ⭐ | Markdown |
|
|
27
|
+
| | [Retrieve page](https://developers.notion.com/reference/retrieve-a-page) | `retrieve-page` | simple/json |
|
|
28
|
+
| | [Update page](https://developers.notion.com/reference/patch-page) | `update-page` | JSON |
|
|
29
|
+
| | [Retrieve page property](https://developers.notion.com/reference/retrieve-a-page-property-item) | `retrieve-page-property` | JSON |
|
|
30
|
+
| | [Move page](https://developers.notion.com/reference/post-page-move) | `move-page` | JSON |
|
|
31
|
+
| **データベース** | | | |
|
|
32
|
+
| | [Create database](https://developers.notion.com/reference/create-a-database) | `create-database` | JSON |
|
|
33
|
+
| | [Retrieve database](https://developers.notion.com/reference/retrieve-a-database) | `retrieve-database` | simple/json |
|
|
34
|
+
| | [Update database](https://developers.notion.com/reference/update-a-database) | `update-database` | JSON |
|
|
35
|
+
| | [Query database](https://developers.notion.com/reference/post-database-query) | `query-database` | simple/json |
|
|
36
|
+
| **ブロック** | | | |
|
|
37
|
+
| | [Retrieve block](https://developers.notion.com/reference/retrieve-a-block) | `retrieve-block` | markdown/json |
|
|
38
|
+
| | [Update block](https://developers.notion.com/reference/update-a-block) | `update-block` | JSON |
|
|
39
|
+
| | | `update-block-simple` ⭐ | Markdown |
|
|
40
|
+
| | [Delete block](https://developers.notion.com/reference/delete-a-block) | `delete-block` | JSON |
|
|
41
|
+
| | [Retrieve block children](https://developers.notion.com/reference/get-block-children) | `get-block-children` | markdown/json |
|
|
42
|
+
| | [Append block children](https://developers.notion.com/reference/patch-block-children) | `append-block-children` | JSON |
|
|
43
|
+
| | | `append-blocks-simple` ⭐ | Markdown |
|
|
44
|
+
| **コメント** | | | |
|
|
45
|
+
| | [Create comment](https://developers.notion.com/reference/create-a-comment) | `create-comment` | JSON |
|
|
46
|
+
| | [List comments](https://developers.notion.com/reference/retrieve-comments) | `list-comments` | JSON |
|
|
47
|
+
| **ユーザー** | | | |
|
|
48
|
+
| | [List users](https://developers.notion.com/reference/get-users) | `list-users` | JSON |
|
|
49
|
+
| | [Retrieve user](https://developers.notion.com/reference/get-user) | `retrieve-user` | JSON |
|
|
50
|
+
| | [Retrieve bot user](https://developers.notion.com/reference/get-self) | `retrieve-bot-user` | JSON |
|
|
51
|
+
| **検索** | | | |
|
|
52
|
+
| | [Search](https://developers.notion.com/reference/post-search) | `search` | JSON |
|
|
53
|
+
|
|
54
|
+
⭐ = Markdown入力対応(入力トークン約80%削減)
|
|
17
55
|
|
|
18
56
|
## インストール
|
|
19
57
|
|
|
@@ -110,6 +148,45 @@ Claude Desktopの設定ファイル(macOSの場合: `~/.config/claude/claude_d
|
|
|
110
148
|
}
|
|
111
149
|
```
|
|
112
150
|
|
|
151
|
+
### create-page-simple ⭐
|
|
152
|
+
|
|
153
|
+
Markdownを使ってページを作成します。`create-page`と比較して**出力トークン約80%削減**。
|
|
154
|
+
|
|
155
|
+
**パラメータ:**
|
|
156
|
+
- `database_id` (必須): ページを作成するデータベースのID
|
|
157
|
+
- `title` (必須): ページタイトル(文字列)
|
|
158
|
+
- `content` (任意): ページ本文(Markdown形式)
|
|
159
|
+
- `properties` (任意): 追加のNotionプロパティ
|
|
160
|
+
- `icon` (任意): 絵文字アイコン(例: "🐛")
|
|
161
|
+
|
|
162
|
+
**サポートするMarkdown記法:**
|
|
163
|
+
- 見出し: `# ## ###` (####以上はheading_3にフォールバック)
|
|
164
|
+
- リスト: `- ` または `* ` (箇条書き)、`1. ` (番号付き)
|
|
165
|
+
- チェックボックス: `- [ ]` / `- [x]`
|
|
166
|
+
- コードブロック: ` ``` ` (言語指定対応)
|
|
167
|
+
- 引用: `> `
|
|
168
|
+
- 区切り線: `---`
|
|
169
|
+
- 画像: ``
|
|
170
|
+
- インライン: `**太字**`、`*イタリック*`、`~~取り消し線~~`、`` `コード` ``、`[リンク](url)`
|
|
171
|
+
|
|
172
|
+
```json
|
|
173
|
+
{
|
|
174
|
+
"database_id": "データベースのUUID",
|
|
175
|
+
"title": "バグレポート",
|
|
176
|
+
"content": "## 再現手順\n\n1. ログイン\n2. 設定を開く\n\n## 期待動作\n\n正常に表示される",
|
|
177
|
+
"properties": {
|
|
178
|
+
"Status": { "status": { "name": "Open" } }
|
|
179
|
+
},
|
|
180
|
+
"icon": "🐛"
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**トークン比較:**
|
|
185
|
+
| 方式 | トークン数 | 削減率 |
|
|
186
|
+
|------|-----------|--------|
|
|
187
|
+
| create-page (ブロック構造) | ~152 | - |
|
|
188
|
+
| create-page-simple (Markdown) | ~26 | **83%** |
|
|
189
|
+
|
|
113
190
|
### update-page
|
|
114
191
|
|
|
115
192
|
ページのプロパティを更新します。
|
|
@@ -250,6 +327,30 @@ Claude Desktopの設定ファイル(macOSの場合: `~/.config/claude/claude_d
|
|
|
250
327
|
}
|
|
251
328
|
```
|
|
252
329
|
|
|
330
|
+
### append-blocks-simple ⭐
|
|
331
|
+
|
|
332
|
+
Markdownを使ってブロックを追加します。`append-block-children`と比較して**出力トークン約80%削減**。
|
|
333
|
+
|
|
334
|
+
**パラメータ:**
|
|
335
|
+
- `block_id` (必須): 追加先のページまたはブロックのID
|
|
336
|
+
- `content` (必須): 追加するコンテンツ(Markdown形式)
|
|
337
|
+
- `after` (任意): このブロックIDの後に挿入
|
|
338
|
+
|
|
339
|
+
`create-page-simple`と同じMarkdown記法をサポートしています。
|
|
340
|
+
|
|
341
|
+
```json
|
|
342
|
+
{
|
|
343
|
+
"block_id": "ページまたはブロックのUUID",
|
|
344
|
+
"content": "# 新しいセクション\n\nこれは**重要な**コンテンツで[リンク](https://example.com)もあります。\n\n- 項目1\n- 項目2\n\n```javascript\nconst x = 1;\n```"
|
|
345
|
+
}
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
**トークン比較:**
|
|
349
|
+
| 方式 | トークン数 | 削減率 |
|
|
350
|
+
|------|-----------|--------|
|
|
351
|
+
| append-block-children (ブロック構造) | ~201 | - |
|
|
352
|
+
| append-blocks-simple (Markdown) | ~42 | **79%** |
|
|
353
|
+
|
|
253
354
|
### create-comment
|
|
254
355
|
|
|
255
356
|
ページにコメントを追加します。
|
package/README.md
CHANGED
|
@@ -8,12 +8,50 @@ MCP (Model Context Protocol) server for Notion API. Enables AI assistants to int
|
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
|
-
- **Page Operations**: Create, retrieve, and
|
|
12
|
-
- **Database Operations**: Create, update, and query databases with filters and sorts
|
|
13
|
-
- **Block Operations**:
|
|
11
|
+
- **Page Operations**: Create, retrieve, update, and move Notion pages
|
|
12
|
+
- **Database Operations**: Create, retrieve, update, and query databases with filters and sorts
|
|
13
|
+
- **Block Operations**: Retrieve, update, delete, and append blocks
|
|
14
14
|
- **Search**: Search across pages and databases
|
|
15
|
-
- **Comments**:
|
|
15
|
+
- **Comments**: Create and list comments
|
|
16
|
+
- **Users**: List users and retrieve user info
|
|
16
17
|
- **Token-Efficient Output**: Markdown/simple format reduces token usage by ~96%
|
|
18
|
+
- **Markdown Input**: Create and append content using Markdown (80% fewer input tokens)
|
|
19
|
+
|
|
20
|
+
## API Coverage
|
|
21
|
+
|
|
22
|
+
| Category | Notion API | MCP Tool | Format |
|
|
23
|
+
|----------|-----------|----------|--------|
|
|
24
|
+
| **Pages** | | | |
|
|
25
|
+
| | [Create page](https://developers.notion.com/reference/post-page) | `create-page` | JSON |
|
|
26
|
+
| | | `create-page-simple` ⭐ | Markdown |
|
|
27
|
+
| | [Retrieve page](https://developers.notion.com/reference/retrieve-a-page) | `retrieve-page` | simple/json |
|
|
28
|
+
| | [Update page](https://developers.notion.com/reference/patch-page) | `update-page` | JSON |
|
|
29
|
+
| | [Retrieve page property](https://developers.notion.com/reference/retrieve-a-page-property-item) | `retrieve-page-property` | JSON |
|
|
30
|
+
| | [Move page](https://developers.notion.com/reference/post-page-move) | `move-page` | JSON |
|
|
31
|
+
| **Databases** | | | |
|
|
32
|
+
| | [Create database](https://developers.notion.com/reference/create-a-database) | `create-database` | JSON |
|
|
33
|
+
| | [Retrieve database](https://developers.notion.com/reference/retrieve-a-database) | `retrieve-database` | simple/json |
|
|
34
|
+
| | [Update database](https://developers.notion.com/reference/update-a-database) | `update-database` | JSON |
|
|
35
|
+
| | [Query database](https://developers.notion.com/reference/post-database-query) | `query-database` | simple/json |
|
|
36
|
+
| **Blocks** | | | |
|
|
37
|
+
| | [Retrieve block](https://developers.notion.com/reference/retrieve-a-block) | `retrieve-block` | markdown/json |
|
|
38
|
+
| | [Update block](https://developers.notion.com/reference/update-a-block) | `update-block` | JSON |
|
|
39
|
+
| | | `update-block-simple` ⭐ | Markdown |
|
|
40
|
+
| | [Delete block](https://developers.notion.com/reference/delete-a-block) | `delete-block` | JSON |
|
|
41
|
+
| | [Retrieve block children](https://developers.notion.com/reference/get-block-children) | `get-block-children` | markdown/json |
|
|
42
|
+
| | [Append block children](https://developers.notion.com/reference/patch-block-children) | `append-block-children` | JSON |
|
|
43
|
+
| | | `append-blocks-simple` ⭐ | Markdown |
|
|
44
|
+
| **Comments** | | | |
|
|
45
|
+
| | [Create comment](https://developers.notion.com/reference/create-a-comment) | `create-comment` | JSON |
|
|
46
|
+
| | [List comments](https://developers.notion.com/reference/retrieve-comments) | `list-comments` | JSON |
|
|
47
|
+
| **Users** | | | |
|
|
48
|
+
| | [List users](https://developers.notion.com/reference/get-users) | `list-users` | JSON |
|
|
49
|
+
| | [Retrieve user](https://developers.notion.com/reference/get-user) | `retrieve-user` | JSON |
|
|
50
|
+
| | [Retrieve bot user](https://developers.notion.com/reference/get-self) | `retrieve-bot-user` | JSON |
|
|
51
|
+
| **Search** | | | |
|
|
52
|
+
| | [Search](https://developers.notion.com/reference/post-search) | `search` | JSON |
|
|
53
|
+
|
|
54
|
+
⭐ = Markdown input supported (reduces input tokens by ~80%)
|
|
17
55
|
|
|
18
56
|
## Installation
|
|
19
57
|
|
|
@@ -110,6 +148,45 @@ Create a new page in a database.
|
|
|
110
148
|
}
|
|
111
149
|
```
|
|
112
150
|
|
|
151
|
+
### create-page-simple ⭐
|
|
152
|
+
|
|
153
|
+
Create a new page using Markdown. **~80% fewer output tokens** compared to `create-page`.
|
|
154
|
+
|
|
155
|
+
**Parameters:**
|
|
156
|
+
- `database_id` (required): The database ID to create the page in
|
|
157
|
+
- `title` (required): Page title as a simple string
|
|
158
|
+
- `content` (optional): Page content in Markdown
|
|
159
|
+
- `properties` (optional): Additional Notion properties
|
|
160
|
+
- `icon` (optional): Emoji icon (e.g., "🐛")
|
|
161
|
+
|
|
162
|
+
**Supported Markdown:**
|
|
163
|
+
- Headings: `# ## ###` (#### and beyond → heading_3)
|
|
164
|
+
- Lists: `- ` or `* ` (bulleted), `1. ` (numbered)
|
|
165
|
+
- Checkboxes: `- [ ]` / `- [x]`
|
|
166
|
+
- Code blocks: ` ``` ` with language
|
|
167
|
+
- Quotes: `> `
|
|
168
|
+
- Dividers: `---`
|
|
169
|
+
- Images: ``
|
|
170
|
+
- Inline: `**bold**`, `*italic*`, `~~strike~~`, `` `code` ``, `[link](url)`
|
|
171
|
+
|
|
172
|
+
```json
|
|
173
|
+
{
|
|
174
|
+
"database_id": "database-uuid-here",
|
|
175
|
+
"title": "Bug Report",
|
|
176
|
+
"content": "## Steps to Reproduce\n\n1. Login\n2. Open settings\n\n## Expected Behavior\n\nShould display correctly",
|
|
177
|
+
"properties": {
|
|
178
|
+
"Status": { "status": { "name": "Open" } }
|
|
179
|
+
},
|
|
180
|
+
"icon": "🐛"
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**Token Comparison:**
|
|
185
|
+
| Method | Tokens | Reduction |
|
|
186
|
+
|--------|--------|-----------|
|
|
187
|
+
| create-page (blocks) | ~152 | - |
|
|
188
|
+
| create-page-simple (markdown) | ~26 | **83%** |
|
|
189
|
+
|
|
113
190
|
### update-page
|
|
114
191
|
|
|
115
192
|
Update a page's properties.
|
|
@@ -250,6 +327,30 @@ Append new blocks to a page or block.
|
|
|
250
327
|
}
|
|
251
328
|
```
|
|
252
329
|
|
|
330
|
+
### append-blocks-simple ⭐
|
|
331
|
+
|
|
332
|
+
Append blocks using Markdown. **~80% fewer output tokens** compared to `append-block-children`.
|
|
333
|
+
|
|
334
|
+
**Parameters:**
|
|
335
|
+
- `block_id` (required): The page or block ID to append to
|
|
336
|
+
- `content` (required): Content in Markdown
|
|
337
|
+
- `after` (optional): Insert after this block ID
|
|
338
|
+
|
|
339
|
+
Same Markdown support as `create-page-simple`.
|
|
340
|
+
|
|
341
|
+
```json
|
|
342
|
+
{
|
|
343
|
+
"block_id": "page-or-block-uuid-here",
|
|
344
|
+
"content": "# New Section\n\nThis is **important** content with a [link](https://example.com).\n\n- Item 1\n- Item 2\n\n```javascript\nconst x = 1;\n```"
|
|
345
|
+
}
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
**Token Comparison:**
|
|
349
|
+
| Method | Tokens | Reduction |
|
|
350
|
+
|--------|--------|-----------|
|
|
351
|
+
| append-block-children (blocks) | ~201 | - |
|
|
352
|
+
| append-blocks-simple (markdown) | ~42 | **79%** |
|
|
353
|
+
|
|
253
354
|
### create-comment
|
|
254
355
|
|
|
255
356
|
Add a comment to a page.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-to-blocks.test.d.ts","sourceRoot":"","sources":["../../../../src/converters/__tests__/markdown-to-blocks.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { markdownToBlocks, parseInlineMarkdown } from '../markdown-to-blocks.js';
|
|
3
|
+
describe('parseInlineMarkdown', () => {
|
|
4
|
+
describe('plain text', () => {
|
|
5
|
+
it('should return plain text as single rich text item', () => {
|
|
6
|
+
const result = parseInlineMarkdown('Hello world');
|
|
7
|
+
expect(result).toEqual([{ type: 'text', text: { content: 'Hello world' } }]);
|
|
8
|
+
});
|
|
9
|
+
it('should handle empty string', () => {
|
|
10
|
+
const result = parseInlineMarkdown('');
|
|
11
|
+
expect(result).toEqual([]);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
describe('bold', () => {
|
|
15
|
+
it('should parse **bold** text', () => {
|
|
16
|
+
const result = parseInlineMarkdown('This is **bold** text');
|
|
17
|
+
expect(result).toHaveLength(3);
|
|
18
|
+
expect(result[0]).toEqual({ type: 'text', text: { content: 'This is ' } });
|
|
19
|
+
expect(result[1]).toEqual({
|
|
20
|
+
type: 'text',
|
|
21
|
+
text: { content: 'bold' },
|
|
22
|
+
annotations: { bold: true },
|
|
23
|
+
});
|
|
24
|
+
expect(result[2]).toEqual({ type: 'text', text: { content: ' text' } });
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe('italic', () => {
|
|
28
|
+
it('should parse *italic* text', () => {
|
|
29
|
+
const result = parseInlineMarkdown('This is *italic* text');
|
|
30
|
+
expect(result).toHaveLength(3);
|
|
31
|
+
expect(result[1]).toEqual({
|
|
32
|
+
type: 'text',
|
|
33
|
+
text: { content: 'italic' },
|
|
34
|
+
annotations: { italic: true },
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe('strikethrough', () => {
|
|
39
|
+
it('should parse ~~strikethrough~~ text', () => {
|
|
40
|
+
const result = parseInlineMarkdown('This is ~~deleted~~ text');
|
|
41
|
+
expect(result).toHaveLength(3);
|
|
42
|
+
expect(result[1]).toEqual({
|
|
43
|
+
type: 'text',
|
|
44
|
+
text: { content: 'deleted' },
|
|
45
|
+
annotations: { strikethrough: true },
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
describe('code', () => {
|
|
50
|
+
it('should parse `code` text', () => {
|
|
51
|
+
const result = parseInlineMarkdown('Use `console.log()` here');
|
|
52
|
+
expect(result).toHaveLength(3);
|
|
53
|
+
expect(result[1]).toEqual({
|
|
54
|
+
type: 'text',
|
|
55
|
+
text: { content: 'console.log()' },
|
|
56
|
+
annotations: { code: true },
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
describe('links', () => {
|
|
61
|
+
it('should parse [text](url) links', () => {
|
|
62
|
+
const result = parseInlineMarkdown('Visit [Google](https://google.com) now');
|
|
63
|
+
expect(result).toHaveLength(3);
|
|
64
|
+
expect(result[1]).toEqual({
|
|
65
|
+
type: 'text',
|
|
66
|
+
text: { content: 'Google', link: { url: 'https://google.com' } },
|
|
67
|
+
annotations: {},
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
describe('markdownToBlocks', () => {
|
|
73
|
+
describe('paragraphs', () => {
|
|
74
|
+
it('should convert plain text to paragraph block', () => {
|
|
75
|
+
const result = markdownToBlocks('Hello world');
|
|
76
|
+
expect(result).toHaveLength(1);
|
|
77
|
+
expect(result[0].type).toBe('paragraph');
|
|
78
|
+
expect(result[0].paragraph).toEqual({
|
|
79
|
+
rich_text: [{ type: 'text', text: { content: 'Hello world' } }],
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
it('should skip empty lines', () => {
|
|
83
|
+
const result = markdownToBlocks('Line 1\n\nLine 2');
|
|
84
|
+
expect(result).toHaveLength(2);
|
|
85
|
+
expect(result[0].type).toBe('paragraph');
|
|
86
|
+
expect(result[1].type).toBe('paragraph');
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
describe('headings', () => {
|
|
90
|
+
it('should convert # to heading_1', () => {
|
|
91
|
+
const result = markdownToBlocks('# Heading 1');
|
|
92
|
+
expect(result).toHaveLength(1);
|
|
93
|
+
expect(result[0].type).toBe('heading_1');
|
|
94
|
+
expect(result[0].heading_1).toEqual({
|
|
95
|
+
rich_text: [{ type: 'text', text: { content: 'Heading 1' } }],
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
it('should convert ## to heading_2', () => {
|
|
99
|
+
const result = markdownToBlocks('## Heading 2');
|
|
100
|
+
expect(result).toHaveLength(1);
|
|
101
|
+
expect(result[0].type).toBe('heading_2');
|
|
102
|
+
});
|
|
103
|
+
it('should convert ### to heading_3', () => {
|
|
104
|
+
const result = markdownToBlocks('### Heading 3');
|
|
105
|
+
expect(result).toHaveLength(1);
|
|
106
|
+
expect(result[0].type).toBe('heading_3');
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
describe('lists', () => {
|
|
110
|
+
it('should convert - to bulleted_list_item', () => {
|
|
111
|
+
const result = markdownToBlocks('- Item 1\n- Item 2');
|
|
112
|
+
expect(result).toHaveLength(2);
|
|
113
|
+
expect(result[0].type).toBe('bulleted_list_item');
|
|
114
|
+
expect(result[1].type).toBe('bulleted_list_item');
|
|
115
|
+
});
|
|
116
|
+
it('should convert * to bulleted_list_item', () => {
|
|
117
|
+
const result = markdownToBlocks('* Item 1');
|
|
118
|
+
expect(result).toHaveLength(1);
|
|
119
|
+
expect(result[0].type).toBe('bulleted_list_item');
|
|
120
|
+
});
|
|
121
|
+
it('should convert 1. to numbered_list_item', () => {
|
|
122
|
+
const result = markdownToBlocks('1. First\n2. Second');
|
|
123
|
+
expect(result).toHaveLength(2);
|
|
124
|
+
expect(result[0].type).toBe('numbered_list_item');
|
|
125
|
+
expect(result[1].type).toBe('numbered_list_item');
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
describe('checkboxes', () => {
|
|
129
|
+
it('should convert - [ ] to unchecked to_do', () => {
|
|
130
|
+
const result = markdownToBlocks('- [ ] Task');
|
|
131
|
+
expect(result).toHaveLength(1);
|
|
132
|
+
expect(result[0].type).toBe('to_do');
|
|
133
|
+
expect(result[0].to_do).toEqual({
|
|
134
|
+
rich_text: [{ type: 'text', text: { content: 'Task' } }],
|
|
135
|
+
checked: false,
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
it('should convert - [x] to checked to_do', () => {
|
|
139
|
+
const result = markdownToBlocks('- [x] Done');
|
|
140
|
+
expect(result).toHaveLength(1);
|
|
141
|
+
expect(result[0].type).toBe('to_do');
|
|
142
|
+
expect(result[0].to_do.checked).toBe(true);
|
|
143
|
+
});
|
|
144
|
+
it('should handle - [X] (uppercase)', () => {
|
|
145
|
+
const result = markdownToBlocks('- [X] Done');
|
|
146
|
+
expect(result[0].to_do.checked).toBe(true);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
describe('code blocks', () => {
|
|
150
|
+
it('should convert ``` to code block', () => {
|
|
151
|
+
const result = markdownToBlocks('```\nconst x = 1\n```');
|
|
152
|
+
expect(result).toHaveLength(1);
|
|
153
|
+
expect(result[0].type).toBe('code');
|
|
154
|
+
expect(result[0].code).toEqual({
|
|
155
|
+
rich_text: [{ type: 'text', text: { content: 'const x = 1' } }],
|
|
156
|
+
language: 'plain text',
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
it('should parse language from code fence', () => {
|
|
160
|
+
const result = markdownToBlocks('```typescript\nconst x: number = 1\n```');
|
|
161
|
+
expect(result[0].code.language).toBe('typescript');
|
|
162
|
+
});
|
|
163
|
+
it('should handle multi-line code', () => {
|
|
164
|
+
const result = markdownToBlocks('```js\nline1\nline2\nline3\n```');
|
|
165
|
+
const code = result[0].code;
|
|
166
|
+
expect(code.rich_text[0].text.content).toBe('line1\nline2\nline3');
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
describe('quotes', () => {
|
|
170
|
+
it('should convert > to quote block', () => {
|
|
171
|
+
const result = markdownToBlocks('> This is a quote');
|
|
172
|
+
expect(result).toHaveLength(1);
|
|
173
|
+
expect(result[0].type).toBe('quote');
|
|
174
|
+
expect(result[0].quote).toEqual({
|
|
175
|
+
rich_text: [{ type: 'text', text: { content: 'This is a quote' } }],
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
it('should combine consecutive quote lines', () => {
|
|
179
|
+
const result = markdownToBlocks('> Line 1\n> Line 2');
|
|
180
|
+
expect(result).toHaveLength(1);
|
|
181
|
+
const quote = result[0].quote;
|
|
182
|
+
expect(quote.rich_text[0].text.content).toBe('Line 1\nLine 2');
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
describe('dividers', () => {
|
|
186
|
+
it('should convert --- to divider', () => {
|
|
187
|
+
const result = markdownToBlocks('---');
|
|
188
|
+
expect(result).toHaveLength(1);
|
|
189
|
+
expect(result[0].type).toBe('divider');
|
|
190
|
+
expect(result[0].divider).toEqual({});
|
|
191
|
+
});
|
|
192
|
+
it('should handle ---- (multiple dashes)', () => {
|
|
193
|
+
const result = markdownToBlocks('----');
|
|
194
|
+
expect(result[0].type).toBe('divider');
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
describe('images', () => {
|
|
198
|
+
it('should convert  to image block', () => {
|
|
199
|
+
const result = markdownToBlocks('');
|
|
200
|
+
expect(result).toHaveLength(1);
|
|
201
|
+
expect(result[0].type).toBe('image');
|
|
202
|
+
expect(result[0].image).toEqual({
|
|
203
|
+
type: 'external',
|
|
204
|
+
external: { url: 'https://example.com/image.png' },
|
|
205
|
+
caption: [{ type: 'text', text: { content: 'Alt text' } }],
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
it('should handle image without alt text', () => {
|
|
209
|
+
const result = markdownToBlocks('');
|
|
210
|
+
expect(result[0].image.caption).toEqual([]);
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
describe('mixed content', () => {
|
|
214
|
+
it('should handle complex markdown document', () => {
|
|
215
|
+
const markdown = `# Title
|
|
216
|
+
|
|
217
|
+
This is a paragraph with **bold** and *italic*.
|
|
218
|
+
|
|
219
|
+
## Section
|
|
220
|
+
|
|
221
|
+
- Item 1
|
|
222
|
+
- Item 2
|
|
223
|
+
|
|
224
|
+
\`\`\`javascript
|
|
225
|
+
const x = 1
|
|
226
|
+
\`\`\`
|
|
227
|
+
|
|
228
|
+
> A quote
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
`;
|
|
233
|
+
const result = markdownToBlocks(markdown);
|
|
234
|
+
expect(result[0].type).toBe('heading_1');
|
|
235
|
+
expect(result[1].type).toBe('paragraph');
|
|
236
|
+
expect(result[2].type).toBe('heading_2');
|
|
237
|
+
expect(result[3].type).toBe('bulleted_list_item');
|
|
238
|
+
expect(result[4].type).toBe('bulleted_list_item');
|
|
239
|
+
expect(result[5].type).toBe('code');
|
|
240
|
+
expect(result[6].type).toBe('quote');
|
|
241
|
+
expect(result[7].type).toBe('divider');
|
|
242
|
+
expect(result[8].type).toBe('image');
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
});
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Notion APIから取得したデータをマークダウンやシンプルな形式に変換する機能を提供
|
|
5
5
|
*/
|
|
6
6
|
export { blocksToMarkdown, blocksToMarkdownSync, type ConvertOptions, type NotionBlock, } from './block-to-markdown.js';
|
|
7
|
+
export { markdownToBlocks, parseInlineMarkdown } from './markdown-to-blocks.js';
|
|
7
8
|
export { type NotionProperty, type PropertyValue, pagePropertiesToObject, pagePropertiesToSimple, pagesToSimple, pageToSimple, type SimplePage, type SimpleProperty, } from './page-to-markdown.js';
|
|
8
9
|
export { type RichTextItem, richTextToMarkdown, richTextToPlain, } from './rich-text-to-markdown.js';
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/converters/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,KAAK,cAAc,EACnB,KAAK,WAAW,GACjB,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,aAAa,EACb,YAAY,EACZ,KAAK,UAAU,EACf,KAAK,cAAc,GACpB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EACL,KAAK,YAAY,EACjB,kBAAkB,EAClB,eAAe,GAChB,MAAM,4BAA4B,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/converters/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,KAAK,cAAc,EACnB,KAAK,WAAW,GACjB,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAE/E,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,aAAa,EACb,YAAY,EACZ,KAAK,UAAU,EACf,KAAK,cAAc,GACpB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EACL,KAAK,YAAY,EACjB,kBAAkB,EAClB,eAAe,GAChB,MAAM,4BAA4B,CAAA"}
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
// ブロック変換
|
|
7
7
|
export { blocksToMarkdown, blocksToMarkdownSync, } from './block-to-markdown.js';
|
|
8
|
+
// Markdown→ブロック変換
|
|
9
|
+
export { markdownToBlocks, parseInlineMarkdown } from './markdown-to-blocks.js';
|
|
8
10
|
// ページプロパティ変換
|
|
9
11
|
export { pagePropertiesToObject, pagePropertiesToSimple, pagesToSimple, pageToSimple, } from './page-to-markdown.js';
|
|
10
12
|
// RichText変換
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown文字列をNotionブロック配列に変換するモジュール
|
|
3
|
+
*/
|
|
4
|
+
import type { RichTextItem } from './rich-text-to-markdown.js';
|
|
5
|
+
/**
|
|
6
|
+
* Notionブロックの型定義(簡易版)
|
|
7
|
+
*/
|
|
8
|
+
export interface NotionBlock {
|
|
9
|
+
type: string;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* インラインMarkdown記法をRichText配列に変換
|
|
14
|
+
* サポート: **bold**, *italic*, ~~strike~~, `code`, [text](url)
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseInlineMarkdown(text: string): RichTextItem[];
|
|
17
|
+
/**
|
|
18
|
+
* Markdown文字列をNotionブロック配列に変換
|
|
19
|
+
*/
|
|
20
|
+
export declare function markdownToBlocks(markdown: string): NotionBlock[];
|
|
21
|
+
//# sourceMappingURL=markdown-to-blocks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-to-blocks.d.ts","sourceRoot":"","sources":["../../../src/converters/markdown-to-blocks.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAO9D;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,EAAE,CA8HhE;AAmBD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,EAAE,CA8HhE"}
|