Skip to content

Hotfix #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/check-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Comment PR
if: github.base_ref == 'master' && github.head_ref != 'next'
if: github.base_ref == 'master' && github.head_ref != 'staging'
uses: thollander/actions-comment-pull-request@v2
with:
message: |
We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the next branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch.
- name: Check branch
if: github.base_ref == 'master' && github.head_ref != 'next'
if: github.base_ref == 'master' && github.head_ref != 'staging'
run: |
echo "ERROR: We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the next branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch."
exit 1
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

### Version: 1.0.5
#### Date: Oct-10-2024
- Used Class Name and Id property in JsonToHTML converter

### Version: 1.0.4
#### Date: Aug-21-2024
- Classname and ID property support in text node
Expand Down
5 changes: 3 additions & 2 deletions Contentstack.Utils.Tests/Constants/JsonToHtmlConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static class JsonToHtmlResultConstants
public const string kLinkInPMailToHtml = "<p style=\"text-align:left;\"><strong><em><u><sub></sub></u></em></strong><a href=\"mailto:support@contentstack.com\">LINK</a></p>";
public const string kLinkInPMailToTARGEtHtml = "<p style=\"text-align:left;\"><strong><em><u><sub></sub></u></em></strong><a href=\"mailto:support@contentstack.com\" target=\"_self\">LINK</a></p>";
public const string kEmbedHtml = "<iframe src=\"https://www.youtube.com/watch?v=AOP0yARiW8U\"></iframe>";
public const string stringClassIdResult = "<p><span id=\"i3\">This</span> is a <span class=\"c1\" id=\"i1\">text</span> to be <span class=\"c2\">ignored</span></p>" ;
}

public static class JsonToHtmlConstants
Expand Down Expand Up @@ -47,8 +48,8 @@ public static class JsonToHtmlConstants
public const string kEntryReferenceLinkJson = "{ \"uid\":\"06e34a7 5e4 e549d\", \"_version\":1, \"attrs\":{ }, \"children\":[{\"uid\":\"7626ea98e0e95d602210\",\"type\":\"reference\",\"attrs\":{\"target\":\"_self\",\"href\":\"/copy-of-entry-final-02\",\"display-type\":\"link\",\"entry-uid\":\"UID_08\",\"content-type-uid\":\"embeddedrte\",\"locale\":\"en-us\",\"type\":\"entry\",\"class-name\":\"embedded-entry\"},\"children\":[{\"text\":\"/copy-of-entry-final-02\"}]}],\"type\":\"doc\"}";
public const string kEntryReferenceInlineJson = "{ \"uid\":\"06e34a7 5e4 e549d\", \"_version\":1, \"attrs\":{ }, \"children\":[{\"uid\":\"506 4878f3f46 s21f0cbc aff\",\"type\":\"reference\",\"attrs\":{\"display-type\":\"inline\",\"entry-uid\":\"UID_09\",\"content-type-uid\":\"embeddedrte\",\"locale\":\"en-us\",\"type\":\"entry\",\"class-name\":\"embedded-entry\"},\"children\":[{\"text\":\"\"}]}],\"type\":\"doc\"}";
public const string kHRJson = "{ \"uid\":\"06e34a7 5e4 e549d\", \"_version\":1, \"attrs\":{ }, \"children\":[{\"uid\":\"f5a7b57 40a8a5c3 576828276b\",\"type\":\"hr\",\"children\":[{\"text\":\"\"}],\"attrs\":{ }}],\"type\":\"doc\"}";


public const string classId = "{ \"uid\":\"06e34a7 5e4 e549d\", \"_version\":1, \"attrs\":{ }, \"children\":[{\"uid\":\"f5a7b57 40a8a5c3 576828276b\",\"type\":\"doc\",\"children\":[{\"text\":\"Thorisbest\",\"classname\": \"c2\",\"id\": \"i2\"}],\"attrs\":{ }}],\"type\":\"text\"}";
public const string stringClassId = "{ \"type\": \"doc\", \"attrs\": {}, \"uid\": \"8622288a91dc4c76985d776d2540b395\", \"children\": [ { \"type\": \"p\", \"uid\": \"396ee25abd0f4296a45eac63809450ef\", \"attrs\": {}, \"children\": [ { \"text\": \"This\", \"classname\": \"\", \"id\": \"i3\" }, { \"text\": \" is a \" }, { \"text\": \"text\", \"classname\": \"c1\", \"id\": \"i1\" }, { \"text\": \" to be \" }, { \"text\": \"ignored\", \"classname\": \"c2\", \"id\": \"\" } ] } ], \"_version\": 4 }";
public const string KAssetNode = "\"embedded_itemsConnection\": { \"edges\": [{ \"node\": { \"system\": { \"content_type_uid\": \"sys_assets\", \"uid\": \"UID_12\" }, \"created_at\": \"2020-08-19T09:13:32.785Z\", \"updated_at\": \"2020-08-19T09:13:32.785Z\", \"created_by\": \"Created_at\", \"updated_by\": \"Created_at\", \"content_type\": \"application/pdf\", \"file_size\": \"13264\", \"filename\": \"dummy.pdf\", \"url\":\"/v3/assetsUID_12/dummy.pdf\", \"_version\": 1, \"title\": \"dummy.pdf\" } } ]}";
public const string KEntryBlocNode = "\"embedded_itemsConnection\": { \"edges\": [{ \"node\": { \"title\": \"Update this title\", \"url\": \"\", \"locale\": \"en-us\", \"system\": { \"uid\": \"UID_07\", \"content_type_uid\": \"content_block\" }, \"_version\": 5, \"_in_progress\": false, \"multi_line\": \"\", \"rich_text_editor\": \"\" } } ]}";
public const string KEntryLinkNode = "\"embedded_itemsConnection\": { \"edges\": [{ \"node\": { \"title\": \"Entry with embedded entry\", \"rich_text_editor\": [ \"\" ], \"locale\": \"en-us\", \"system\": { \"uid\": \"UID_08\", \"content_type_uid\": \"embeddedrte\" }, \"_in_progress\": false } } ]}";
Expand Down
10 changes: 10 additions & 0 deletions Contentstack.Utils.Tests/JsonToHtmlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -479,5 +479,15 @@ public void Should_Return_Result_For_Array_Hr_Document()

Assert.Equal(new List<string>() { "<hr>" }, result);
}

[Fact]
public void TestForClassandId()
{
Node node = NodeParser.parse(JsonToHtmlConstants.stringClassId);

var result = Utils.JsonToHtml(new List<Node>() { node }, defaultRender);

Assert.Equal(new List<string>() { JsonToHtmlResultConstants.stringClassIdResult }, result);
}
}
}
2 changes: 1 addition & 1 deletion Contentstack.Utils.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Global
{EB2B5E23-E45F-4C6C-BF98-FE3971DE4250}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
version = 1.0.4
version = 1.0.5
Policies = $0
$0.DotNetNamingPolicy = $1
$1.DirectoryNamespaceAssociation = PrefixedHierarchical
Expand Down
12 changes: 10 additions & 2 deletions Contentstack.Utils/Enums/MarkType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ public enum MarkType
/// <summary>
/// This will specify the Mark type of text node as Superscript
/// </summary>
Superscript
}
Superscript,
/// <summary>
/// This will specify the class selector
/// </summary>
Class,
/// <summary>
/// This will specify the id selector
/// </summary>
Id
}
}
2 changes: 1 addition & 1 deletion Contentstack.Utils/Interfaces/IOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Contentstack.Utils.Interfaces
public interface IRenderable
{
string RenderOption(IEmbeddedObject entry, Metadata metadata);
string RenderMark(MarkType markType, string text);
string RenderMark(MarkType markType, string text, string className, string Id);
string RenderNode(string nodeType, Node node, NodeChildrenCallBack callBack);
}
}
7 changes: 6 additions & 1 deletion Contentstack.Utils/Models/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public virtual string RenderOption(IEmbeddedObject embeddedObject, Metadata meta
return "";
}

public virtual string RenderMark(MarkType markType, string text)
public virtual string RenderMark(MarkType markType, string text, string className = "", string id = "")
{
switch (markType)
{
Expand All @@ -84,6 +84,11 @@ public virtual string RenderMark(MarkType markType, string text)
return $"<sub>{text}</sub>";
case MarkType.Superscript:
return $"<sup>{text}</sup>";
case MarkType.Id:
case MarkType.Class:
string classAttr = !string.IsNullOrEmpty(className) ? $" class=\"{className}\"" : "";
string idAttr = !string.IsNullOrEmpty(id) ? $" id=\"{id}\"" : "";
return $"<span{classAttr}{idAttr}>{text}</span>";
}
return text;
}
Expand Down
4 changes: 4 additions & 0 deletions Contentstack.Utils/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ private static string textToHtml(TextNode textNode, Options options)
{
text = options.RenderMark(MarkType.Bold, text: text);
}
if (!string.IsNullOrEmpty(textNode.classname) || !string.IsNullOrEmpty(textNode.id))
{
text = options.RenderMark(MarkType.Class, text: text, textNode.classname, textNode.id);
}
return text;
}

Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<Version>1.0.4</Version>
<Version>1.0.5</Version>
</PropertyGroup>
</Project>
Loading