Skip to content

Commit

Permalink
2.0.0-pre2
Browse files Browse the repository at this point in the history
  • Loading branch information
softlion committed Nov 26, 2023
1 parent 80d014b commit 1bb44da
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 34 deletions.
10 changes: 7 additions & 3 deletions NotionSharp.ApiClient.Tests/JsonData/AboutThis.expected.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ <h1><div class="notion-line">Some API</div></h1>
<ul><li><div class="notion-line">LoadPageChunk</div></li></ul>
<ul><li><div class="notion-line">GetSyndicationFeed</div></li></ul>
<div class="notion-paragraph"></div>
<div class="notion-paragraph"><div class="notion-line">♓ The last one is the most powerful: it creates a rss like feed from a </div><div class="notion-line"><a href="http://notion.so/" class=" notion-color-default notion-code"><a href="http://notion.so/">notion</a></a></div><div class="notion-line"> collection. The only difficulty is to obtain a login cookie that is long enough to live on a server.</div></div>
<div class="notion-paragraph"><div class="notion-line">♓ The last one is the most powerful: it creates a rss like feed from a </div><div class="notion-line"><a href="http://notion.so/" class=" notion-color-default notion-code"><a href="http://notion.so/">notion</a></a></div><div class="notion-line"> collection. It opens cool things like creating a full website from a notion page hierarchy.</div></div>
<div class="notion-paragraph"></div>
<div class="notion-callout-block notion-block-color-graybackground"><img class="notion-emoji" src="https://cdn.jsdelivr.net/gh/twitter/twemoji/assets/svg/1f4e2.svg" />
<div class="notion-line">This is a CallOut !</div></div>
<div class="notion-paragraph"></div>
<div class="notion-column_list-block"><div style="display: flex"></div></div><div class="notion-paragraph"></div>
<div class="notion-column_list-block"><div style="display: flex"><div class="notion-column" style="width: calc((100% - 46px) * 1);"><div class="notion-paragraph"><div class="notion-line"><span class=" notion-color-orange notion-code">First Column (25%)
</span></div></div>
</div><div class="notion-column-separator"><div class="notion-column-separator-line"></div></div><div class="notion-column" style="width: calc((100% - 46px) * 1);"><div class="notion-paragraph"><div class="notion-line"><span class=" notion-color-green notion-code">Second column (75%)</span></div></div>
<div class="notion-image-block"><img src="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&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45HZZMZUHI%2F20231126%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20231126T192115Z&X-Amz-Expires=3600&X-Amz-Signature=8a77a96d1ea398bb4a8bc0ab44ab6b2c1b0ad57a1e83fcaf238e825cbc1c5938&X-Amz-SignedHeaders=host&x-id=GetObject"/></div>
</div></div></div><div class="notion-paragraph"></div>
<div class="notion-quote-block notion-block-color-default>"><div class="notion-line">The End Quote</div></div>
<div class="notion-paragraph"></div>
<div class="notion-paragraph"></div>
2 changes: 1 addition & 1 deletion NotionSharp.ApiClient/Lib/HtmlRendering/HtmlRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ protected virtual void TransformColumnList(Block block, StringBuilder sb)

var columnIndex = 0;
var totalColumns = block.Children.Count;
foreach (var columnBlock in block.Children)
foreach (var columnBlock in block.Children) //type=BlockTypes.Column
{
var endColumn = result.StartColumn(columnIndex);
foreach (var contentBlock in columnBlock.Children)
Expand Down
30 changes: 4 additions & 26 deletions NotionSharp.ApiClient/Lib/PublicApi/Model/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ public static class BlockTypes
public const string File = "file";
public const string Callout = "callout";
public const string ColumnList = "column_list";
public const string Column = "column";

public static readonly string[] SupportedBlocks =
{
BulletedListItem, Callout, //ChildDatabase,
//ChildPage,
ColumnList,
ColumnList, Column,
//When the is_toggleable property is true
Heading1, Heading2, Heading3,
NumberedListItem, Paragraph, Image, Quote, File, //SyncedBlock, Table, Template,
Expand All @@ -41,7 +42,7 @@ public static class BlockTypes
public static readonly string[] BlocksWithChildren =
{
BulletedListItem, Callout, //ChildDatabase,
ChildPage, ColumnList,
ChildPage, ColumnList, Column,
//When the is_toggleable property is true
Heading1, Heading2, Heading3,
NumberedListItem, Paragraph, Quote, //SyncedBlock, Table, Template,
Expand Down Expand Up @@ -76,27 +77,7 @@ public enum NotionColor
}


/*
Block types that support child blocks
Some block types contain nested blocks. The following block types support child blocks:
Bulleted list item
Callout
Child database
Child page
Column
Heading 1, when the is_toggleable property is true
Heading 2, when the is_toggleable property is true
Heading 3, when the is_toggleable property is true
Numbered list item
Paragraph
Quote
Synced block
Table
Template
To do
Toggle
*/

public class Block : NamedObject, IBlockId
{
#region common props
Expand Down Expand Up @@ -186,6 +167,3 @@ public record NotionEmoji(string Type, string Emoji) : NotionBaseType(Type);
[BufferedJsonDerivedType(typeof(NotionFile), "file")]
[BufferedJsonDerivedType(typeof(NotionEmoji), "emoji")]
public abstract record NotionBaseType(string Type);

// public record BlockColumnList(List<BlockColumnData> Columns);
// public record BlockColumnData(Block ColumnBlock, float Ratio);
10 changes: 7 additions & 3 deletions NotionSharp.ApiClient/NotionSessionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,18 @@ public static async Task<string> GetHtml(this NotionSession session, Page page,
if (blocks.Count == 0)
return string.Empty;

var blockWithChildren = blocks.Where(b => b.HasChildren && BlockTypes.BlocksWithChildren.Contains(b.Type)).ToList();
foreach (var block in blockWithChildren)
var blockWithChildren = new Queue<Block>(blocks.Where(b => b.HasChildren && BlockTypes.BlocksWithChildren.Contains(b.Type)));
while (blockWithChildren.Count != 0)
{
var block = blockWithChildren.Dequeue();
await session.GetChildren(block, cancel);
//recursive
blockWithChildren.AddRange(block.Children.Where(b => b.HasChildren && BlockTypes.BlocksWithChildren.Contains(b.Type)));
var children = block.Children.Where(b => b.HasChildren && BlockTypes.BlocksWithChildren.Contains(b.Type));
foreach (var child in children)
blockWithChildren.Enqueue(child);
}


return new HtmlRenderer().GetHtml(blocks);
}

Expand Down
2 changes: 1 addition & 1 deletion NotionSharp.ApiClient/NotionSharp.ApiClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PropertyGroup>
<!-- nuget configurable properties -->
<Version>2.0.0</Version>
<VersionSuffix>-pre1</VersionSuffix>
<VersionSuffix>-pre2</VersionSuffix>
<DefineConstants>$(DefineConstants);</DefineConstants>
</PropertyGroup>

Expand Down

0 comments on commit 1bb44da

Please sign in to comment.