Skip to content

Commit

Permalink
fix colors
Browse files Browse the repository at this point in the history
  • Loading branch information
softlion committed Jan 18, 2024
1 parent 663ebf7 commit a17eef8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions NotionSharp.ApiClient.Tests/JsonData/AboutThis.expected.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ <h1><div class="notion-line">Some API</div></h1>
<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/"><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-callout-block notion-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 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%2F20231127%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20231127T072100Z&X-Amz-Expires=3600&X-Amz-Signature=ae13232280da11ebbf30f754f3e48f26f6023621f97b9f7b812fd86ac6bebef7&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-quote-block notion-color-default>"><div class="notion-line">The End Quote</div></div>
<div class="notion-paragraph"></div>
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ public static class HtmlBlockExtensions
{
public static string? GetColor(this NotionColor color)
{
if (color == NotionColor.Default)
return null;

//TODO: replace tolower by ToSnakeCase
return ((string?)TypeDescriptor.GetConverter(color).ConvertTo(color, typeof(string)))?.ToLower();
}


public static string? GetColor(this NotionColor? color) => color?.GetColor();

/// <summary>
/// TODO: switch to https://github.com/twitter/twemoji
/// </summary>
Expand Down
11 changes: 6 additions & 5 deletions NotionSharp.ApiClient/Lib/HtmlRendering/HtmlRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected virtual void TransformQuote(Block block, StringBuilder sb)

sb.Append("<div class=\"notion-quote-block");
if(color != null)
sb.Append($" notion-block-color-{color}>");
sb.Append($" notion-color-{color}>");
sb.Append("\">");

Append(quote, sb);
Expand All @@ -131,7 +131,7 @@ protected virtual void TransformCallout(Block block, StringBuilder sb)

sb.Append("""<div class="notion-callout-block""");
if(color != null)
sb.Append($""" notion-block-color-{color}""");
sb.Append($""" notion-color-{color}""");
sb.Append("\">");

if (callout.Icon is NotionEmoji emoji)
Expand Down Expand Up @@ -325,8 +325,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 is not null and not NotionColor.Default)
sb.Append(" notion-color-").Append(line.Annotation.Color);
var color = line.Annotation.Color.GetColor();
if (color != null)
sb.Append(" notion-color-").Append(line.Annotation.Color.GetColor());
if (line.Annotation.Code)
sb.Append(" notion-code");
sb.Append("\"");
Expand Down Expand Up @@ -416,7 +417,7 @@ protected virtual StringBuilder Append(Mention? mention, StringBuilder sb)
// },
// TransformCallout = (data, block) =>
// {
// sb.AppendLine(@$"<div class=""notion-callout-block notion-block-color-{data.Format.BlockColor}"">");
// sb.AppendLine(@$"<div class=""notion-callout-block notion-color-{data.Format.BlockColor}"">");
//
// if (Uri.TryCreate(data.Format.PageIcon, UriKind.Absolute, out var iconUrl))
// sb.AppendLine(@$"<img class=""notion-icon"" src=""{iconUrl}"" />");
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.1</Version>
<VersionSuffix>-pre3</VersionSuffix>
<VersionSuffix>-pre4</VersionSuffix>
<DefineConstants>$(DefineConstants);</DefineConstants>
</PropertyGroup>

Expand Down

0 comments on commit a17eef8

Please sign in to comment.