コードブロックのキャプションプロパティがサポートされました

開示?
開示?
原題
Caption property is now supported for code block type
日付
Jan 26, 2022
Number
39
前のリリース日(最新)
リリース間隔(日)
作成日
Jan 25, 2022 11:07 PM
タグ
ADDED
経過日数
コードブロックのキャプションがサポートされたとのことで試してみる。まずは概要から。

概要説明

code ブロックタイプの caption の追加、更新、取得のサポートが追加されました。
以下は append block children の結果を示したものです。
{ "object": "list", "results": [ { "object": "block", "id": "block-id", "created_time": "2021-10-14T18:10:00.000Z", "last_edited_time": "2021-10-14T18:10:00.000Z", "has_children": false, "archived": false, "type": "code", "code": { "caption": [ { "type": "text", "text": { "content": "Hello Caption!", "link": null }, "annotations": { "bold": false, "italic": false, "strikethrough": false, "underline": false, "code": false, "color": "default" }, "plain_text": "Hello Caption!", "href": null } ], "text": [ { "type": "text", "text": { "content": "const foo = \"bar\"", "link": null }, "annotations": { "bold": false, "italic": false, "strikethrough": false, "underline": false, "code": false, "color": "default" }, "plain_text": "const foo = \"bar\"", "href": null } ], "language": "javascript" } }, ], "next_cursor": null, "has_more": false }

検証

いつものように検証しましょう。せっかくなので先日サポートされた mermaid を追加してみましょう。
curl -X PATCH 'https://api.notion.com/v1/blocks/6acefcebdbe14939a98aa2f4deb8ec1c/children' \ -H 'Authorization: Bearer '"$NOTION_API_KEY"'' \ -H "Content-Type: application/json" \ -H "Notion-Version: 2021-08-16" \ --data '{ "children": [ { "object": "block", "type": "code", "code": { "caption": [ { "type": "text", "text": { "content": "キャプションを付けたコードブロック" } } ], "text": [ { "type": "text", "text": { "content": "pie title test\n \"りんご\" : 4\n \"みかん\" : 3\n \"梨\" : 2\n \"もも\" : 1\n" } } ], "language": "mermaid" } } ] }'
戻ってきた JSON はこちら。
{ "object": "list", "results": [ { "object": "block", "id": "5a058c49-9051-4db0-8514-aca5ba31a315", "created_time": "2022-01-25T23:56:00.000Z", "last_edited_time": "2022-01-25T23:56:00.000Z", "has_children": false, "archived": false, "type": "code", "code": { "caption": [ { "type": "text", "text": { "content": "キャプションを付けたコードブロック", "link": null }, "annotations": { "bold": false, "italic": false, "strikethrough": false, "underline": false, "code": false, "color": "default" }, "plain_text": "キャプションを付けたコードブロック", "href": null } ], "text": [ { "type": "text", "text": { "content": "pie title test\n \"りんご\" : 4\n \"みかん\" : 3\n \"梨\" : 2\n \"もも\" : 1\n", "link": null }, "annotations": { "bold": false, "italic": false, "strikethrough": false, "underline": false, "code": false, "color": "default" }, "plain_text": "pie title test\n \"りんご\" : 4\n \"みかん\" : 3\n \"梨\" : 2\n \"もも\" : 1\n", "href": null } ], "language": "mermaid" } } ], "next_cursor": null, "has_more": false }
 

実行結果

上のスクリプトでこんな感じのパイチャートが描けました。
pie title test "りんご" : 4 "みかん" : 3 "梨" : 2 "もも" : 1
キャプションを付けたコードブロック

🖇️
Notion API Changelog まとめ