From 1cb650822e07204eff01644e41242ec6b949a82d Mon Sep 17 00:00:00 2001 From: Benjamin Mayrargue Date: Fri, 12 Jan 2024 14:37:19 +0100 Subject: [PATCH] fix multi levels bullets, bold, titles 2 and 3. --- .../JsonData/AboutThis.full.children.json | 1130 ++++++++++++++++- .../JsonData/AboutThis.full.json | 2 +- NotionSharp.ApiClient.Tests/TestNotionBase.cs | 23 +- NotionSharp.ApiClient.Tests/TestNotionHtml.cs | 42 +- .../Lib/HtmlRendering/HtmlRenderer.cs | 24 +- .../Lib/HttpNotionSession.cs | 29 +- .../Lib/PublicApi/Model/Block.cs | 4 +- .../Lib/PublicApi/Model/Common/RichText.cs | 6 +- 8 files changed, 1222 insertions(+), 38 deletions(-) diff --git a/NotionSharp.ApiClient.Tests/JsonData/AboutThis.full.children.json b/NotionSharp.ApiClient.Tests/JsonData/AboutThis.full.children.json index c631cc7..475ebe0 100644 --- a/NotionSharp.ApiClient.Tests/JsonData/AboutThis.full.children.json +++ b/NotionSharp.ApiClient.Tests/JsonData/AboutThis.full.children.json @@ -1 +1,1129 @@ -[{"id":"a5a61607-488d-49ae-b2ee-60a8413deba1","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"paragraph","created_time":"2020-04-30T13:38:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2020-05-27T10:20:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"paragraph":{"rich_text":[{"type":"text","plain_text":"This content is written on a Notion page. It is a demo page for our csharp ","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"This content is written on a Notion page. It is a demo page for our csharp "}},{"type":"text","plain_text":"notion.so","href":"http://notion.so/","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"notion.so","link":{"url":"http://notion.so/"}}},{"type":"text","plain_text":" api client.","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":" api client."}}]},"object":"block"},{"id":"5b08e855-e221-41db-a442-bdc6384414e2","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"paragraph","created_time":"2020-05-27T10:21:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2020-05-27T10:21:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"paragraph":{"rich_text":[]},"object":"block"},{"id":"78598042-5f17-4ae3-8ef7-270e86aa7ae6","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"heading_1","created_time":"2020-05-27T10:20:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2024-01-12T11:02:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"heading_1":{"rich_text":[{"type":"text","plain_text":"Title 1","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"Title 1"}}]},"object":"block"},{"id":"f58ac7ca-8059-4487-8997-59948dd98148","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"heading_2","created_time":"2024-01-12T11:02:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2024-01-12T11:02:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"heading_2":{"rich_text":[{"type":"text","plain_text":"Title 2","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"Title 2"}}]},"object":"block"},{"id":"7919eb3f-cffe-46cb-95d0-8a4f27830a88","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"paragraph","created_time":"2020-04-30T13:39:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2020-05-27T10:20:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"paragraph":{"rich_text":[{"type":"text","plain_text":"It contains some lines to test the api client, especially these methods:","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"It contains some lines to test the api client, especially these methods:"}}]},"object":"block"},{"id":"85148c18-9dcc-4b27-9ca9-b74a15957c40","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"bulleted_list_item","created_time":"2020-04-30T13:39:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2020-04-30T13:39:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"bulleted_list_item":{"rich_text":[{"type":"text","plain_text":"GetHtml","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"GetHtml"}}]},"object":"block"},{"id":"31a6469a-8509-49e8-9033-7d34dfdd11c1","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"bulleted_list_item","created_time":"2020-04-30T13:39:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2020-04-30T13:39:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"bulleted_list_item":{"rich_text":[{"type":"text","plain_text":"LoadPageChunk","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"LoadPageChunk"}}]},"object":"block"},{"id":"72dd306a-1c1e-4c8a-afb0-424c7138cf60","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"bulleted_list_item","created_time":"2020-04-30T13:40:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2020-04-30T13:40:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"bulleted_list_item":{"rich_text":[{"type":"text","plain_text":"GetSyndicationFeed","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"GetSyndicationFeed"}}]},"object":"block"},{"id":"977c714e-b1a4-4911-8afd-6653ae54cd1b","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"paragraph","created_time":"2020-05-27T10:20:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2020-05-27T10:20:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"paragraph":{"rich_text":[]},"object":"block"},{"id":"1e1c8000-dcfa-4dd0-a955-8fe7fd5c6fdf","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"paragraph","created_time":"2020-04-30T13:40:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2023-11-26T17:53:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"paragraph":{"rich_text":[{"type":"text","plain_text":"\u2653 The last one is the most powerful: it creates a rss like feed from a ","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"\u2653 The last one is the most powerful: it creates a rss like feed from a "}},{"type":"text","plain_text":"notion","href":"http://notion.so/","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"notion","link":{"url":"http://notion.so/"}}},{"type":"text","plain_text":" collection. It opens cool things like creating a full website from a notion page hierarchy.","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":" collection. It opens cool things like creating a full website from a notion page hierarchy."}}]},"object":"block"},{"id":"2866f22f-16b3-4cb3-a381-f91f52c9b443","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"paragraph","created_time":"2020-05-27T10:20:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2023-11-26T16:03:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"paragraph":{"rich_text":[]},"object":"block"},{"id":"19766178-d501-4a42-890f-2af001d9f05c","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"callout","created_time":"2020-05-27T10:20:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2023-11-26T16:04:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"callout":{"rich_text":[{"type":"text","plain_text":"This is a CallOut !","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"This is a CallOut !"}}],"color":"gray_background","icon":{"emoji":"\uD83D\uDCE2","type":"emoji"}},"object":"block"},{"id":"9a68013d-d6ec-4a3f-96ed-2f392bad52b8","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"paragraph","created_time":"2023-11-26T16:03:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2023-11-26T16:04:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"paragraph":{"rich_text":[]},"object":"block"},{"id":"66930c42-ed4c-48dd-be36-2e8e1b9a4459","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"column_list","created_time":"2023-11-26T16:05:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2023-11-26T16:05:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":true,"object":"block"},{"id":"d3ca09fc-48da-41ef-afb8-a1307a1e9cfa","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"paragraph","created_time":"2023-11-26T16:06:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2023-11-26T16:07:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"paragraph":{"rich_text":[]},"object":"block"},{"id":"a8fd2706-3222-467e-a9c5-3cb47df50b43","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"quote","created_time":"2023-11-26T16:06:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2023-11-26T16:07:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"quote":{"color":"default","rich_text":[{"type":"text","plain_text":"The End Quote","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"The End Quote"}}]},"object":"block"},{"id":"502ec809-7326-4a71-a546-89a6d1e92cf8","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"paragraph","created_time":"2023-11-26T16:07:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2023-11-26T16:07:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"paragraph":{"rich_text":[]},"object":"block"}] \ No newline at end of file +[ + { + "id": "a5a61607-488d-49ae-b2ee-60a8413deba1", + "parent": { + "type": "page_id", + "page_id": "c7b44455-3d31-4a5b-b82c-b7e3d85ba585" + }, + "type": "paragraph", + "created_time": "2020-04-30T13:38:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2020-05-27T10:20:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": false, + "paragraph": { + "rich_text": [ + { + "type": "text", + "plain_text": "This content is written on a Notion page. It is a demo page for our csharp ", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "text": { + "content": "This content is written on a Notion page. It is a demo page for our csharp " + } + }, + { + "type": "text", + "plain_text": "notion.so", + "href": "http://notion.so/", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "text": { + "content": "notion.so", + "link": { + "url": "http://notion.so/" + } + } + }, + { + "type": "text", + "plain_text": " api client.", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "text": { + "content": " api client." + } + } + ] + }, + "object": "block" + }, + { + "id": "5b08e855-e221-41db-a442-bdc6384414e2", + "parent": { + "type": "page_id", + "page_id": "c7b44455-3d31-4a5b-b82c-b7e3d85ba585" + }, + "type": "paragraph", + "created_time": "2020-05-27T10:21:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2020-05-27T10:21:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": false, + "paragraph": { + "rich_text": [] + }, + "object": "block" + }, + { + "id": "78598042-5f17-4ae3-8ef7-270e86aa7ae6", + "parent": { + "type": "page_id", + "page_id": "c7b44455-3d31-4a5b-b82c-b7e3d85ba585" + }, + "type": "heading_1", + "created_time": "2020-05-27T10:20:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2024-01-12T11:02:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": false, + "heading_1": { + "rich_text": [ + { + "type": "text", + "plain_text": "Title 1", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "text": { + "content": "Title 1" + } + } + ] + }, + "object": "block" + }, + { + "id": "f58ac7ca-8059-4487-8997-59948dd98148", + "parent": { + "type": "page_id", + "page_id": "c7b44455-3d31-4a5b-b82c-b7e3d85ba585" + }, + "type": "heading_2", + "created_time": "2024-01-12T11:02:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2024-01-12T11:02:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": false, + "heading_2": { + "rich_text": [ + { + "type": "text", + "plain_text": "Title 2", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "text": { + "content": "Title 2" + } + } + ] + }, + "object": "block" + }, + { + "id": "27e8f2b1-8065-439c-8d7d-7a63d7b73d1c", + "parent": { + "type": "page_id", + "page_id": "c7b44455-3d31-4a5b-b82c-b7e3d85ba585" + }, + "type": "paragraph", + "created_time": "2024-01-12T12:33:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2024-01-12T12:33:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": false, + "paragraph": { + "rich_text": [ + { + "type": "text", + "plain_text": "Bold text", + "annotations": { + "bold": true, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "text": { + "content": "Bold text" + } + } + ] + }, + "object": "block" + }, + { + "id": "58465b22-d524-49b4-90dd-0af6871d1264", + "parent": { + "type": "page_id", + "page_id": "c7b44455-3d31-4a5b-b82c-b7e3d85ba585" + }, + "type": "bulleted_list_item", + "created_time": "2024-01-12T12:34:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2024-01-12T12:34:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": true, + "children": [ + { + "id": "a32c9c51-8903-4252-a7e3-3cb287287386", + "parent": { + "type": "block_id", + "block_id": "58465b22-d524-49b4-90dd-0af6871d1264" + }, + "type": "bulleted_list_item", + "created_time": "2024-01-12T12:34:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2024-01-12T12:34:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": true, + "children": [ + { + "id": "553b8af2-638b-4598-8872-f51a42f14207", + "parent": { + "type": "block_id", + "block_id": "a32c9c51-8903-4252-a7e3-3cb287287386" + }, + "type": "bulleted_list_item", + "created_time": "2024-01-12T12:34:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2024-01-12T12:34:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": true, + "children": [ + { + "id": "24f1ed9b-ec74-4806-9f66-a02c3e38469a", + "parent": { + "type": "block_id", + "block_id": "553b8af2-638b-4598-8872-f51a42f14207" + }, + "type": "bulleted_list_item", + "created_time": "2024-01-12T12:34:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2024-01-12T12:34:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": true, + "children": [ + { + "id": "1fafade9-1d60-463f-9647-a6b2834bb71c", + "parent": { + "type": "block_id", + "block_id": "24f1ed9b-ec74-4806-9f66-a02c3e38469a" + }, + "type": "bulleted_list_item", + "created_time": "2024-01-12T12:34:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2024-01-12T12:34:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": true, + "children": [ + { + "id": "fb4c4391-ef58-439e-9244-1f013e06e393", + "parent": { + "type": "block_id", + "block_id": "1fafade9-1d60-463f-9647-a6b2834bb71c" + }, + "type": "bulleted_list_item", + "created_time": "2024-01-12T12:34:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2024-01-12T12:34:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": true, + "children": [ + { + "id": "846c9889-fc89-4693-b19b-ee890f2c1c59", + "parent": { + "type": "block_id", + "block_id": "fb4c4391-ef58-439e-9244-1f013e06e393" + }, + "type": "bulleted_list_item", + "created_time": "2024-01-12T12:34:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2024-01-12T12:34:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": false, + "bulleted_list_item": { + "rich_text": [ + { + "type": "text", + "plain_text": "Level 7", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "text": { + "content": "Level 7" + } + } + ] + }, + "object": "block" + } + ], + "bulleted_list_item": { + "rich_text": [ + { + "type": "text", + "plain_text": "Level 6", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "text": { + "content": "Level 6" + } + } + ] + }, + "object": "block" + } + ], + "bulleted_list_item": { + "rich_text": [ + { + "type": "text", + "plain_text": "Level 5", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "text": { + "content": "Level 5" + } + } + ] + }, + "object": "block" + } + ], + "bulleted_list_item": { + "rich_text": [ + { + "type": "text", + "plain_text": "Level 4", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "text": { + "content": "Level 4" + } + } + ] + }, + "object": "block" + } + ], + "bulleted_list_item": { + "rich_text": [ + { + "type": "text", + "plain_text": "Level 3", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "text": { + "content": "Level 3" + } + } + ] + }, + "object": "block" + } + ], + "bulleted_list_item": { + "rich_text": [ + { + "type": "text", + "plain_text": "Level 2", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "text": { + "content": "Level 2" + } + } + ] + }, + "object": "block" + } + ], + "bulleted_list_item": { + "rich_text": [ + { + "type": "text", + "plain_text": "Level1", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "text": { + "content": "Level1" + } + } + ] + }, + "object": "block" + }, + { + "id": "7919eb3f-cffe-46cb-95d0-8a4f27830a88", + "parent": { + "type": "page_id", + "page_id": "c7b44455-3d31-4a5b-b82c-b7e3d85ba585" + }, + "type": "paragraph", + "created_time": "2020-04-30T13:39:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2020-05-27T10:20:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": false, + "paragraph": { + "rich_text": [ + { + "type": "text", + "plain_text": "It contains some lines to test the api client, especially these methods:", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "text": { + "content": "It contains some lines to test the api client, especially these methods:" + } + } + ] + }, + "object": "block" + }, + { + "id": "85148c18-9dcc-4b27-9ca9-b74a15957c40", + "parent": { + "type": "page_id", + "page_id": "c7b44455-3d31-4a5b-b82c-b7e3d85ba585" + }, + "type": "bulleted_list_item", + "created_time": "2020-04-30T13:39:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2024-01-12T12:34:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": false, + "bulleted_list_item": { + "rich_text": [ + { + "type": "text", + "plain_text": "GetHtml", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "text": { + "content": "GetHtml" + } + } + ] + }, + "object": "block" + }, + { + "id": "cc76d615-cefa-45d9-aca3-cae671dd6b37", + "parent": { + "type": "page_id", + "page_id": "c7b44455-3d31-4a5b-b82c-b7e3d85ba585" + }, + "type": "bulleted_list_item", + "created_time": "2024-01-12T12:34:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2024-01-12T12:34:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": false, + "bulleted_list_item": { + "rich_text": [ + { + "type": "text", + "plain_text": "LoadPageChunk", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "text": { + "content": "LoadPageChunk" + } + } + ] + }, + "object": "block" + }, + { + "id": "72dd306a-1c1e-4c8a-afb0-424c7138cf60", + "parent": { + "type": "page_id", + "page_id": "c7b44455-3d31-4a5b-b82c-b7e3d85ba585" + }, + "type": "bulleted_list_item", + "created_time": "2020-04-30T13:40:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2020-04-30T13:40:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": false, + "bulleted_list_item": { + "rich_text": [ + { + "type": "text", + "plain_text": "GetSyndicationFeed", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "text": { + "content": "GetSyndicationFeed" + } + } + ] + }, + "object": "block" + }, + { + "id": "977c714e-b1a4-4911-8afd-6653ae54cd1b", + "parent": { + "type": "page_id", + "page_id": "c7b44455-3d31-4a5b-b82c-b7e3d85ba585" + }, + "type": "paragraph", + "created_time": "2020-05-27T10:20:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2020-05-27T10:20:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": false, + "paragraph": { + "rich_text": [] + }, + "object": "block" + }, + { + "id": "1e1c8000-dcfa-4dd0-a955-8fe7fd5c6fdf", + "parent": { + "type": "page_id", + "page_id": "c7b44455-3d31-4a5b-b82c-b7e3d85ba585" + }, + "type": "paragraph", + "created_time": "2020-04-30T13:40:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2023-11-26T17:53:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": false, + "paragraph": { + "rich_text": [ + { + "type": "text", + "plain_text": "\u2653 The last one is the most powerful: it creates a rss like feed from a ", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "text": { + "content": "\u2653 The last one is the most powerful: it creates a rss like feed from a " + } + }, + { + "type": "text", + "plain_text": "notion", + "href": "http://notion.so/", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "text": { + "content": "notion", + "link": { + "url": "http://notion.so/" + } + } + }, + { + "type": "text", + "plain_text": " collection. It opens cool things like creating a full website from a notion page hierarchy.", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "text": { + "content": " collection. It opens cool things like creating a full website from a notion page hierarchy." + } + } + ] + }, + "object": "block" + }, + { + "id": "2866f22f-16b3-4cb3-a381-f91f52c9b443", + "parent": { + "type": "page_id", + "page_id": "c7b44455-3d31-4a5b-b82c-b7e3d85ba585" + }, + "type": "paragraph", + "created_time": "2020-05-27T10:20:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2023-11-26T16:03:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": false, + "paragraph": { + "rich_text": [] + }, + "object": "block" + }, + { + "id": "19766178-d501-4a42-890f-2af001d9f05c", + "parent": { + "type": "page_id", + "page_id": "c7b44455-3d31-4a5b-b82c-b7e3d85ba585" + }, + "type": "callout", + "created_time": "2020-05-27T10:20:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2023-11-26T16:04:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": false, + "callout": { + "rich_text": [ + { + "type": "text", + "plain_text": "This is a CallOut !", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "text": { + "content": "This is a CallOut !" + } + } + ], + "color": "gray_background", + "icon": { + "emoji": "\uD83D\uDCE2", + "type": "emoji" + } + }, + "object": "block" + }, + { + "id": "9a68013d-d6ec-4a3f-96ed-2f392bad52b8", + "parent": { + "type": "page_id", + "page_id": "c7b44455-3d31-4a5b-b82c-b7e3d85ba585" + }, + "type": "paragraph", + "created_time": "2023-11-26T16:03:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2023-11-26T16:04:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": false, + "paragraph": { + "rich_text": [] + }, + "object": "block" + }, + { + "id": "66930c42-ed4c-48dd-be36-2e8e1b9a4459", + "parent": { + "type": "page_id", + "page_id": "c7b44455-3d31-4a5b-b82c-b7e3d85ba585" + }, + "type": "column_list", + "created_time": "2023-11-26T16:05:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2023-11-26T16:05:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": true, + "children": [ + { + "id": "53cbb49f-eb91-4407-9072-3c158ed1ef18", + "parent": { + "type": "block_id", + "block_id": "66930c42-ed4c-48dd-be36-2e8e1b9a4459" + }, + "type": "column", + "created_time": "2023-11-26T16:05:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2023-11-26T16:06:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": true, + "children": [ + { + "id": "adfef9bd-a913-473e-9de2-e5dd2812fe09", + "parent": { + "type": "block_id", + "block_id": "53cbb49f-eb91-4407-9072-3c158ed1ef18" + }, + "type": "paragraph", + "created_time": "2023-11-26T16:04:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2023-11-26T16:06:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": false, + "paragraph": { + "rich_text": [ + { + "type": "text", + "plain_text": "First Column (25%)\n", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "orange" + }, + "text": { + "content": "First Column (25%)\n" + } + } + ] + }, + "object": "block" + } + ], + "object": "block" + }, + { + "id": "dd0e16ae-080c-4ed0-96be-666159f17343", + "parent": { + "type": "block_id", + "block_id": "66930c42-ed4c-48dd-be36-2e8e1b9a4459" + }, + "type": "column", + "created_time": "2023-11-26T16:05:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2023-11-26T16:06:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": true, + "children": [ + { + "id": "314477d6-8955-49c8-8ffa-f6302537369e", + "parent": { + "type": "block_id", + "block_id": "dd0e16ae-080c-4ed0-96be-666159f17343" + }, + "type": "paragraph", + "created_time": "2023-11-26T16:04:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2023-11-26T16:07:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": false, + "paragraph": { + "rich_text": [ + { + "type": "text", + "plain_text": "Second column (75%)", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "green" + }, + "text": { + "content": "Second column (75%)" + } + } + ] + }, + "object": "block" + }, + { + "id": "175e7376-ba5c-4b56-ad9c-c5390c817e09", + "parent": { + "type": "block_id", + "block_id": "dd0e16ae-080c-4ed0-96be-666159f17343" + }, + "type": "image", + "created_time": "2023-11-26T16:05:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2023-11-26T16:05:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": false, + "image": { + "file": { + "url": "https://prod-files-secure.s3.us-west-2.amazonaws.com/da89a8e0-9c55-4c13-9966-796e0f0c1bac/3b632032-656f-4e87-87b7-b95bcb786f9d/Untitled.png?X-Amz-Algorithm=AWS4-HMAC-SHA256\u0026X-Amz-Content-Sha256=UNSIGNED-PAYLOAD\u0026X-Amz-Credential=AKIAT73L2G45HZZMZUHI%2F20240112%2Fus-west-2%2Fs3%2Faws4_request\u0026X-Amz-Date=20240112T131938Z\u0026X-Amz-Expires=3600\u0026X-Amz-Signature=4a7d18333c0e39b278886df1631c04fb15b180fb6eacfe3dee0aabbd8a78a948\u0026X-Amz-SignedHeaders=host\u0026x-id=GetObject", + "expiry_time": "2024-01-12T14:19:38.300Z" + }, + "type": "file" + }, + "object": "block" + } + ], + "object": "block" + } + ], + "object": "block" + }, + { + "id": "d3ca09fc-48da-41ef-afb8-a1307a1e9cfa", + "parent": { + "type": "page_id", + "page_id": "c7b44455-3d31-4a5b-b82c-b7e3d85ba585" + }, + "type": "paragraph", + "created_time": "2023-11-26T16:06:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2023-11-26T16:07:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": false, + "paragraph": { + "rich_text": [] + }, + "object": "block" + }, + { + "id": "a8fd2706-3222-467e-a9c5-3cb47df50b43", + "parent": { + "type": "page_id", + "page_id": "c7b44455-3d31-4a5b-b82c-b7e3d85ba585" + }, + "type": "quote", + "created_time": "2023-11-26T16:06:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2023-11-26T16:07:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": false, + "quote": { + "color": "default", + "rich_text": [ + { + "type": "text", + "plain_text": "The End Quote", + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "text": { + "content": "The End Quote" + } + } + ] + }, + "object": "block" + }, + { + "id": "502ec809-7326-4a71-a546-89a6d1e92cf8", + "parent": { + "type": "page_id", + "page_id": "c7b44455-3d31-4a5b-b82c-b7e3d85ba585" + }, + "type": "paragraph", + "created_time": "2023-11-26T16:07:00+00:00", + "created_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "last_edited_time": "2023-11-26T16:07:00+00:00", + "last_edited_by": { + "id": "ab9257e1-d027-4494-8792-71d90b63dd35", + "object": "user" + }, + "archived": false, + "has_children": false, + "paragraph": { + "rich_text": [] + }, + "object": "block" + } +] \ No newline at end of file diff --git a/NotionSharp.ApiClient.Tests/JsonData/AboutThis.full.json b/NotionSharp.ApiClient.Tests/JsonData/AboutThis.full.json index e1e12f0..a64a7d7 100644 --- a/NotionSharp.ApiClient.Tests/JsonData/AboutThis.full.json +++ b/NotionSharp.ApiClient.Tests/JsonData/AboutThis.full.json @@ -1 +1 @@ -{"id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585","created_time":"2020-04-30T13:37:00+00:00","last_edited_time":"2023-11-26T17:53:00+00:00","archived":false,"created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"url":"https://www.notion.so/About-this-c7b444553d314a5bb82cb7e3d85ba585","public_url":"https://wise-spirit-737.notion.site/About-this-c7b444553d314a5bb82cb7e3d85ba585","parent":{"page_id":"18dfbe55-5d7c-416e-9485-7855d4a3949e","type":"page_id"},"properties":{"title":{"title":[{"type":"text","plain_text":"About this","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"About this"}}],"id":"title","type":"title"}},"object":"page"} \ No newline at end of file +{"id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585","created_time":"2020-04-30T13:37:00+00:00","last_edited_time":"2024-01-12T12:34:00+00:00","archived":false,"created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"url":"https://www.notion.so/About-this-c7b444553d314a5bb82cb7e3d85ba585","public_url":"https://wise-spirit-737.notion.site/About-this-c7b444553d314a5bb82cb7e3d85ba585","parent":{"page_id":"18dfbe55-5d7c-416e-9485-7855d4a3949e","type":"page_id"},"properties":{"title":{"title":[{"type":"text","plain_text":"About this","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"About this"}}],"id":"title","type":"title"}},"object":"page"} \ No newline at end of file diff --git a/NotionSharp.ApiClient.Tests/TestNotionBase.cs b/NotionSharp.ApiClient.Tests/TestNotionBase.cs index 9a0ed61..b5742f1 100644 --- a/NotionSharp.ApiClient.Tests/TestNotionBase.cs +++ b/NotionSharp.ApiClient.Tests/TestNotionBase.cs @@ -253,7 +253,7 @@ public async Task TestPageAndChildrenDeserialization() } [TestMethod] - [Ignore("Run this manually to create the json files")] + //[Ignore("Run this manually to create the json files")] public async Task TestPageAndChildrenSerialization() { var session = new NotionSession(TestUtils.CreateOfficialNotionSessionInfo()); @@ -261,26 +261,19 @@ public async Task TestPageAndChildrenSerialization() Assert.AreEqual("About this", page?.Title()?.Title.FirstOrDefault()?.PlainText); var blocks = await session.GetBlockChildren(page.Id).ToListAsync(); - var blockWithChildren = new Queue(blocks.Where(b => b.HasChildren && BlockTypes.BlocksWithChildren.Contains(b.Type))); - while (blockWithChildren.Count != 0) - { - var block = blockWithChildren.Dequeue(); - await session.GetChildren(block); - //recursive - var children = block.Children.Where(b => b.HasChildren && BlockTypes.BlocksWithChildren.Contains(b.Type)); - foreach (var child in children) - blockWithChildren.Enqueue(child); - } + var errBlocks = blocks.Where(b => b.HasChildren && !BlockTypes.BlocksWithChildren.Contains(b.Type)).ToList(); + Assert.AreEqual(0, errBlocks.Count); + await session.LoadChildBlocks(blocks); - var pageJson = JsonSerializer.Serialize(page, HttpNotionSession.NotionJsonSerializationOptions); - var blocksJson = JsonSerializer.Serialize(blocks, HttpNotionSession.NotionJsonSerializationOptions); + var pageJson = JsonSerializer.Serialize(page, HttpNotionSession.NotionJsonFullSerializationOptions); + var blocksJson = JsonSerializer.Serialize(blocks, HttpNotionSession.NotionJsonFullSerializationOptions); var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); await File.WriteAllTextAsync(Path.Combine(path, "AboutThis.full.json"), pageJson); await File.WriteAllTextAsync(Path.Combine(path, "AboutThis.full.children.json"), blocksJson); - var page2 = JsonSerializer.Deserialize(pageJson, HttpNotionSession.NotionJsonSerializationOptions); + var page2 = JsonSerializer.Deserialize(pageJson, HttpNotionSession.NotionJsonFullSerializationOptions); Assert.IsNotNull(page2); - var blocks2 = JsonSerializer.Deserialize>(blocksJson, HttpNotionSession.NotionJsonSerializationOptions); + var blocks2 = JsonSerializer.Deserialize>(blocksJson, HttpNotionSession.NotionJsonFullSerializationOptions); Assert.IsNotNull(blocks2); Assert.AreEqual(blocks.Count,blocks2.Count); } diff --git a/NotionSharp.ApiClient.Tests/TestNotionHtml.cs b/NotionSharp.ApiClient.Tests/TestNotionHtml.cs index 54752e6..15a0de0 100644 --- a/NotionSharp.ApiClient.Tests/TestNotionHtml.cs +++ b/NotionSharp.ApiClient.Tests/TestNotionHtml.cs @@ -54,7 +54,7 @@ public async Task TestGetPage() public async Task TestGetHtml_Link() { var blocksJson = await File.ReadAllTextAsync(Path.Combine(Environment.CurrentDirectory, "JsonData", "AboutThis.full.children.json")); - var blocks = JsonSerializer.Deserialize>(blocksJson, HttpNotionSession.NotionJsonSerializationOptions); + var blocks = JsonSerializer.Deserialize>(blocksJson, HttpNotionSession.NotionJsonFullSerializationOptions); var expectedFilePath = "AboutThis.blocks.link.html"; var blockIndex = 0; @@ -69,7 +69,7 @@ public async Task TestGetHtml_Link() public async Task TestGetHtml_Title1() { var blocksJson = await File.ReadAllTextAsync(Path.Combine(Environment.CurrentDirectory, "JsonData", "AboutThis.full.children.json")); - var blocks = JsonSerializer.Deserialize>(blocksJson, HttpNotionSession.NotionJsonSerializationOptions); + var blocks = JsonSerializer.Deserialize>(blocksJson, HttpNotionSession.NotionJsonFullSerializationOptions); var blockIndex = 2; @@ -83,7 +83,7 @@ public async Task TestGetHtml_Title1() public async Task TestGetHtml_Title2() { var blocksJson = await File.ReadAllTextAsync(Path.Combine(Environment.CurrentDirectory, "JsonData", "AboutThis.full.children.json")); - var blocks = JsonSerializer.Deserialize>(blocksJson, HttpNotionSession.NotionJsonSerializationOptions); + var blocks = JsonSerializer.Deserialize>(blocksJson, HttpNotionSession.NotionJsonFullSerializationOptions); var blockIndex = 3; @@ -92,6 +92,42 @@ public async Task TestGetHtml_Title2() var expectedHtml = """

Title 2

""" + "\r\n"; Assert.AreEqual(expectedHtml, html); } + + [TestMethod] + public async Task TestGetHtml_Bold() + { + var blocksJson = await File.ReadAllTextAsync(Path.Combine(Environment.CurrentDirectory, "JsonData", "AboutThis.full.children.json")); + var blocks = JsonSerializer.Deserialize>(blocksJson, HttpNotionSession.NotionJsonFullSerializationOptions); + + var blockIndex = 4; + + var block = blocks.Skip(blockIndex).Take(1).ToList(); + var html = new HtmlRenderer().GetHtml(block); + var expectedHtml = """
Bold text
""" + "\r\n"; + Assert.AreEqual(expectedHtml, html); + } + + + [TestMethod] + public async Task TestGetHtml_Bullet_Levels2() + { + var blocksJson = await File.ReadAllTextAsync(Path.Combine(Environment.CurrentDirectory, "JsonData", "AboutThis.full.children.json")); + var blocks = JsonSerializer.Deserialize>(blocksJson, HttpNotionSession.NotionJsonFullSerializationOptions); + + var blockIndex = 5; + + var block = blocks.Skip(blockIndex).Take(1).ToList(); + var html = new HtmlRenderer().GetHtml(block); + var expectedHtml = @"
  • Level1
    • Level 2
      • Level 3
        • Level 4
          • Level 5
            • Level 6
              • Level 7
              +
            +
          +
        +
      +
    +
+"; + Assert.AreEqual(expectedHtml, html); + } // [TestMethod] // public void TestGetHtml_SubBullets() diff --git a/NotionSharp.ApiClient/Lib/HtmlRendering/HtmlRenderer.cs b/NotionSharp.ApiClient/Lib/HtmlRendering/HtmlRenderer.cs index 5f1f1b7..629a1dd 100644 --- a/NotionSharp.ApiClient/Lib/HtmlRendering/HtmlRenderer.cs +++ b/NotionSharp.ApiClient/Lib/HtmlRendering/HtmlRenderer.cs @@ -208,6 +208,11 @@ protected virtual void TransformBulletedListItem(Block block, StringBuilder sb) { sb.Append("
  • "); Append(block.BulletedListItem, sb); + if (block?.Children != null) + { + foreach (var child in block.Children) + Transform(child, sb, false); + } sb.AppendLine("
"); } @@ -215,6 +220,11 @@ protected virtual void TransformNumberedListItem(Block block, StringBuilder sb) { sb.Append("
  1. "); Append(block.NumberedListItem, sb); + if (block?.Children != null) + { + foreach (var child in block.Children) + Transform(child, sb, false); + } sb.AppendLine("
"); } @@ -268,19 +278,21 @@ protected virtual StringBuilder Append(RichText? line, StringBuilder sb) return sb; sb.Append("
"); - var tag = line.HasAttribute ? (line.Href != null ? "a" : "span") : null; + var hasAnnotations = line.Annotation?.HasAnnotation == true; + var hasLink = !string.IsNullOrWhiteSpace(line.Href); + var tag = hasLink ? "a" : hasAnnotations ? "span" : null; if (tag != null) { sb.Append("<").Append(tag); - if (line.Href != null) + if (hasLink) sb.Append(" href=\"").Append(Uri.EscapeUriString(line.Href)).Append("\""); - if (line.HasStyle) + if (hasAnnotations) { sb.Append(" class=\""); - if (line.Annotation.Bold) + if (line.Annotation!.Bold) sb.Append(" notion-bold"); if (line.Annotation.Italic) sb.Append(" notion-italic"); @@ -288,9 +300,9 @@ protected virtual StringBuilder Append(RichText? line, StringBuilder sb) sb.Append(" notion-strikethrough"); if (line.Annotation.Underline) sb.Append(" notion-underline"); - if (line.Annotation.Color != null) + if (line.Annotation.Color is not null and not NotionColor.Default) sb.Append(" notion-color-").Append(line.Annotation.Color); - if (line.Annotation?.Code != null) + if (line.Annotation.Code) sb.Append(" notion-code"); sb.Append("\""); } diff --git a/NotionSharp.ApiClient/Lib/HttpNotionSession.cs b/NotionSharp.ApiClient/Lib/HttpNotionSession.cs index 21dd91f..3a6727a 100644 --- a/NotionSharp.ApiClient/Lib/HttpNotionSession.cs +++ b/NotionSharp.ApiClient/Lib/HttpNotionSession.cs @@ -90,19 +90,34 @@ public class HttpNotionSession public static JsonSerializerOptions NotionJsonSerializationOptions { get; } = new (JsonSerializerDefaults.General) { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, - //PropertyNameCaseInsensitive = true, PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower, DictionaryKeyPolicy = JsonNamingPolicy.SnakeCaseLower, - TypeInfoResolver = NotionJsonContext.Default.WithAddedModifier(AddModifiers) //JsonTypeInfoResolver.Combine(NotionJsonContext.Default) //.WithAddedModifier(AddNestedDerivedTypes)) + TypeInfoResolver = NotionJsonContext.Default.WithAddedModifier(ModifierIgnoreBlockChildren) + //JsonTypeInfoResolver.Combine(NotionJsonContext.Default) //.WithAddedModifier(AddNestedDerivedTypes)) }; - private static void AddModifiers(JsonTypeInfo jsonTypeInfo) + public static JsonSerializerOptions NotionJsonFullSerializationOptions { get; } = new (JsonSerializerDefaults.General) { - if (jsonTypeInfo.Type == typeof(PropertyItem)) + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower, + DictionaryKeyPolicy = JsonNamingPolicy.SnakeCaseLower, + TypeInfoResolver = NotionJsonContext.Default + }; + + private static void ModifierIgnoreBlockChildren(JsonTypeInfo jsonTypeInfo) + { + // if (jsonTypeInfo.Type == typeof(PropertyItem)) + // { + // //JsonDerivedType ignores JsonConverter on target type + // var c = jsonTypeInfo.Converter; + // var i = 0; + // } + + if (jsonTypeInfo.Type.IsAssignableTo(typeof(Block))) { - //JsonDerivedType ignores JsonConverter on target type - var c = jsonTypeInfo.Converter; - var i = 0; + var prop = jsonTypeInfo.Properties.FirstOrDefault(p => p.Name == nameof(Block.Children)); + if (prop is not null) + prop.ShouldSerialize = (_, _) => false; } } diff --git a/NotionSharp.ApiClient/Lib/PublicApi/Model/Block.cs b/NotionSharp.ApiClient/Lib/PublicApi/Model/Block.cs index d3175f7..32dae08 100644 --- a/NotionSharp.ApiClient/Lib/PublicApi/Model/Block.cs +++ b/NotionSharp.ApiClient/Lib/PublicApi/Model/Block.cs @@ -107,7 +107,9 @@ public Block() public bool Archived { get; init; } public bool HasChildren { get; init; } - [JsonIgnore] + //Ignore when reading from or writing to Notion api + //Don't ignore for unit testing, as we save and load json files + //Note: Ignored using the Modifiers in HttpNotionSession public List Children { get; set; } #endregion diff --git a/NotionSharp.ApiClient/Lib/PublicApi/Model/Common/RichText.cs b/NotionSharp.ApiClient/Lib/PublicApi/Model/Common/RichText.cs index e735c7e..d0aedfd 100644 --- a/NotionSharp.ApiClient/Lib/PublicApi/Model/Common/RichText.cs +++ b/NotionSharp.ApiClient/Lib/PublicApi/Model/Common/RichText.cs @@ -25,10 +25,8 @@ public class RichText [JsonPropertyName("annotations")] public RichTextAnnotation? Annotation { get; init; } - [JsonIgnore] - public bool HasAttribute => Annotation?.HasAnnotation == true || !string.IsNullOrWhiteSpace(Href); - [JsonIgnore] - public bool HasStyle => Annotation?.HasColor == true; + //[JsonIgnore] + //public bool HasStyle => Annotation?.HasColor == true; #endregion public RichTextText? Text { get; init; } //type=text