From dbc30d83cb69a1ec80d4cd8c3d2ecd354f0a1b6f Mon Sep 17 00:00:00 2001 From: raj pandey Date: Wed, 9 Oct 2024 14:42:51 +0530 Subject: [PATCH 1/2] used the className and id property and version bump --- CHANGELOG.md | 4 ++++ .../Constants/JsonToHtmlConstants.cs | 5 +++-- Contentstack.Utils.Tests/JsonToHtmlTest.cs | 10 ++++++++++ Contentstack.Utils.sln | 2 +- Contentstack.Utils/Enums/MarkType.cs | 12 ++++++++++-- Contentstack.Utils/Interfaces/IOptions.cs | 2 +- Contentstack.Utils/Models/Options.cs | 7 ++++++- Contentstack.Utils/Utils.cs | 4 ++++ Directory.Build.props | 2 +- 9 files changed, 40 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d6f68e..5bd0842 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Contentstack.Utils.Tests/Constants/JsonToHtmlConstants.cs b/Contentstack.Utils.Tests/Constants/JsonToHtmlConstants.cs index 061336e..09d6761 100644 --- a/Contentstack.Utils.Tests/Constants/JsonToHtmlConstants.cs +++ b/Contentstack.Utils.Tests/Constants/JsonToHtmlConstants.cs @@ -20,6 +20,7 @@ public static class JsonToHtmlResultConstants public const string kLinkInPMailToHtml = "

LINK

"; public const string kLinkInPMailToTARGEtHtml = "

LINK

"; public const string kEmbedHtml = ""; + public const string stringClassIdResult = "

This is a text to be ignored

" ; } public static class JsonToHtmlConstants @@ -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 } } ]}"; diff --git a/Contentstack.Utils.Tests/JsonToHtmlTest.cs b/Contentstack.Utils.Tests/JsonToHtmlTest.cs index 62c06e9..9f4b4e1 100644 --- a/Contentstack.Utils.Tests/JsonToHtmlTest.cs +++ b/Contentstack.Utils.Tests/JsonToHtmlTest.cs @@ -479,5 +479,15 @@ public void Should_Return_Result_For_Array_Hr_Document() Assert.Equal(new List() { "
" }, result); } + + [Fact] + public void TestForClassandId() + { + Node node = NodeParser.parse(JsonToHtmlConstants.stringClassId); + + var result = Utils.JsonToHtml(new List() { node }, defaultRender); + + Assert.Equal(new List() { JsonToHtmlResultConstants.stringClassIdResult }, result); + } } } diff --git a/Contentstack.Utils.sln b/Contentstack.Utils.sln index 85e4cc7..12afb40 100644 --- a/Contentstack.Utils.sln +++ b/Contentstack.Utils.sln @@ -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 diff --git a/Contentstack.Utils/Enums/MarkType.cs b/Contentstack.Utils/Enums/MarkType.cs index 11ff58a..cf828f9 100644 --- a/Contentstack.Utils/Enums/MarkType.cs +++ b/Contentstack.Utils/Enums/MarkType.cs @@ -30,6 +30,14 @@ public enum MarkType /// /// This will specify the Mark type of text node as Superscript /// - Superscript - } + Superscript, + /// + /// This will specify the Mark type of text node as Superscript + /// + Class, + /// + /// This will specify the Mark type of text node as Superscript + /// + Id +} } diff --git a/Contentstack.Utils/Interfaces/IOptions.cs b/Contentstack.Utils/Interfaces/IOptions.cs index 6ea9f90..1cccd09 100644 --- a/Contentstack.Utils/Interfaces/IOptions.cs +++ b/Contentstack.Utils/Interfaces/IOptions.cs @@ -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); } } diff --git a/Contentstack.Utils/Models/Options.cs b/Contentstack.Utils/Models/Options.cs index 9f741ab..7cab2fc 100644 --- a/Contentstack.Utils/Models/Options.cs +++ b/Contentstack.Utils/Models/Options.cs @@ -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) { @@ -84,6 +84,11 @@ public virtual string RenderMark(MarkType markType, string text) return $"{text}"; case MarkType.Superscript: return $"{text}"; + case MarkType.Id: + case MarkType.Class: + string classAttr = !string.IsNullOrEmpty(className) ? $" class=\"{className}\"" : ""; + string idAttr = !string.IsNullOrEmpty(id) ? $" id=\"{id}\"" : ""; + return $"{text}"; } return text; } diff --git a/Contentstack.Utils/Utils.cs b/Contentstack.Utils/Utils.cs index 34b6a96..81f4c00 100644 --- a/Contentstack.Utils/Utils.cs +++ b/Contentstack.Utils/Utils.cs @@ -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; } diff --git a/Directory.Build.props b/Directory.Build.props index d5c9309..18f9aae 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 1.0.4 + 1.0.5 From 116d1ce57c39e49b21d38b2183a56f7ab90a497d Mon Sep 17 00:00:00 2001 From: raj pandey Date: Wed, 9 Oct 2024 14:43:05 +0530 Subject: [PATCH 2/2] update marktype --- Contentstack.Utils/Enums/MarkType.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Contentstack.Utils/Enums/MarkType.cs b/Contentstack.Utils/Enums/MarkType.cs index cf828f9..4180f65 100644 --- a/Contentstack.Utils/Enums/MarkType.cs +++ b/Contentstack.Utils/Enums/MarkType.cs @@ -31,12 +31,12 @@ public enum MarkType /// This will specify the Mark type of text node as Superscript /// Superscript, - /// - /// This will specify the Mark type of text node as Superscript - /// + /// + /// This will specify the class selector + /// Class, - /// - /// This will specify the Mark type of text node as Superscript + /// + /// This will specify the id selector /// Id }