Skip to content

Commit 11de0a4

Browse files
authored
Merge pull request #6 from contentstack/feat/CS-44034-fragment-tag-support
feat: ✨ fragment tag support added
2 parents dc678b5 + 368ba0f commit 11de0a4

9 files changed

Lines changed: 82 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
### Version: 1.0.2
33
#### Date: Mar-14-2024
44
- Style attributes supported in converted HTML.
5+
- Fragment tag support added
56

67
### Version: 1.0.1
78
#### Date: July-16-2021

Contentstack.Utils.Tests/Constants/JsonToHtmlConstants.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public static class JsonToHtmlResultConstants
1717
public const string kBlockquoteHtml = "<blockquote>Praesent eu ex sed nibh venenatis pretium.</blockquote>";
1818
public const string kCodeHtml = "<code>Code template.</code>";
1919
public const string kLinkInPHtml = "<p><strong><em><u><sub></sub></u></em></strong><a href=\"LINK.com\">LINK</a></p>";
20+
public const string kLinkInPMailToHtml = "<p><strong><em><u><sub></sub></u></em></strong><a href=\"mailto:support@contentstack.com\">LINK</a></p>";
21+
public const string kLinkInPMailToTARGEtHtml = "<p><strong><em><u><sub></sub></u></em></strong><a href=\"mailto:support@contentstack.com\" target=\"_self\">LINK</a></p>";
2022
public const string kEmbedHtml = "<iframe src=\"https://www.youtube.com/watch?v=AOP0yARiW8U\"></iframe>";
2123
}
2224

@@ -38,6 +40,7 @@ public static class JsonToHtmlConstants
3840
public const string kCodeJson = "{ \"uid\":\"06ea490849d7fc2acd\", \"_version\":13, \"attrs\":{ }, \"children\":[{\"uid\":\"83fba92c91b30002b\",\"type\":\"code\",\"attrs\":{},\"children\":[{\"text\":\"Code template.\"}]}],\"type\":\"doc\"}";
3941
public const string kTableJson = "{ \"uid\": \"06e481190849d7fcd\", \"_version\": 13, \"attrs\": { }, \"children\": [ { \"uid\": \"6dd64343bf634bfadd4\", \"type\": \"table\", \"attrs\": { \"rows\": 4, \"cols\": 2, \"colWidths\": [ 250, 250 ] }, \"children\": [ { \"uid\": \"b9082\", \"type\": \"thead\", \"attrs\": {}, \"children\": [ { \"type\": \"tr\", \"attrs\": {}, \"children\": [ { \"type\": \"th\", \"attrs\": {}, \"children\": [ { \"type\": \"p\", \"attrs\": {}, \"children\": [ { \"text\": \"Header 1\" } ], \"uid\": \"daa3ef\" } ], \"uid\": \"4b3124414a3\" }, { \"type\": \"th\", \"attrs\": { }, \"children\": [ { \"type\": \"p\", \"attrs\": { }, \"children\": [ { \"text\": \"Header 2\" } ], \"uid\": \"eae83c5797d\" } ], \"uid\": \"bca9b6f037a04fb485\" } ], \"uid\": \"b91ae7a48ef2e9da1\" } ] }, { \"type\": \"tbody\", \"attrs\": { }, \"children\": [ { \"type\": \"tr\", \"attrs\": { }, \"children\": [ { \"type\": \"td\", \"attrs\": { }, \"children\": [ { \"type\": \"p\", \"attrs\": { }, \"children\": [ { \"text\": \"Body row 1 data 1\" } ], \"uid\": \"ec674ccc5ce70b7cab\" } ], \"uid\": \"2a70bdeeb99a\" }, { \"type\": \"td\", \"attrs\": { }, \"children\": [ { \"type\": \"p\", \"attrs\": { }, \"children\": [ { \"text\": \"Body row 1 data 2\" } ], \"uid\": \"769a 3f9db34 ce8ec 10486d50\" } ], \"uid\": \"d6407 34a5c6 1ab1e5f7d1\" } ], \"uid\": \"77f6 b951c68 7f9eb397c5\" }, { \"type\": \"tr\", \"attrs\": { }, \"children\": [ { \"type\": \"td\", \"attrs\": { }, \"children\": [ { \"type\": \"p\", \"attrs\": { }, \"children\": [ { \"text\": \"Body row 2 data 1\" } ], \"uid\": \"a6bf 11bb48 630e87d721c0\" } ], \"uid\": \"3da39838b0feaf\" }, { \"type\": \"td\", \"attrs\": { }, \"children\": [ { \"type\": \"p\", \"attrs\": { }, \"children\": [ { \"text\": \"Body row 2 data 2\" } ], \"uid\": \"3b7d12 1f694202 49029e86313\" } ], \"uid\": \"95b38b04abcbc25e94f\" } ], \"uid\": \"b 227fea 8d247013 4f1e1e8\" } ], \"uid\": \"fd5ab86aa642798451b\" } ] }, ], \"type\": \"doc\" }";
4042
public const string kLinkInPJson = "{ \"uid\":\"06e34a7190849d7f2acd\", \"_version\":13, \"attrs\":{ }, \"children\":[{\"type\":\"p\",\"attrs\":{\"style\":{\"text-align\":\"left\"},\"redactor-attributes\":{ }},\"uid\":\"d88dcdf4590dff2d\",\"children\":[{\"text\":\"\",\"bold\":true,\"italic\":true,\"underline\":true,\"subscript\":true},{ \"uid\":\"0d06598201aa8b47\",\"type\":\"a\",\"attrs\":{ \"url\":\"LINK.com\",\"target\":\"_self\"},\"children\":[{ \"text\":\"LINK\"}]},{ \"text\":\"\"}]}],\"type\":\"doc\"}";
43+
public const string kLinkInPMailToJson = "{ \"uid\":\"06e34a7190849d7f2acd\", \"_version\":13, \"attrs\":{ }, \"children\":[{\"type\":\"p\",\"attrs\":{\"style\":{\"text-align\":\"left\"},\"redactor-attributes\":{ }},\"uid\":\"d88dcdf4590dff2d\",\"children\":[{\"text\":\"\",\"bold\":true,\"italic\":true,\"underline\":true,\"subscript\":true},{ \"uid\":\"0d06598201aa8b47\",\"type\":\"a\",\"attrs\":{ \"url\":\"mailto:support@contentstack.com\",\"target\":\"_self\"},\"children\":[{ \"text\":\"LINK\"}]},{ \"text\":\"\"}]}],\"type\":\"doc\"}";
4144
public const string kEmbedJson = "{ \"uid\":\"06e34a7190849d7f2acd\", \"_version\":13, \"attrs\":{ }, \"children\":[{\"uid\":\"251017315905c35d42c9\",\"type\":\"embed\",\"attrs\":{\"url\":\"https://www.youtube.com/watch?v=AOP0yARiW8U\"},\"children\":[{\"text\":\"\"}]}],\"type\":\"doc\"}";
4245
public const string kAssetReferenceJson = "{\"uid\":\"06e34a7 5e4 e549d \", \"_version\":1, \"attrs\":{}, \"children\":[{ \"uid\": \"4f7e33 3390a955 de10c1 c836\", \"type\":\"reference\",\"attrs\":{\"display-type\":\"display\",\"asset-uid\":\"UID_12\",\"content-type-uid\":\"sys_assets\",\"asset-link\":\"https://images.contentstack.com/v3/assets/UID_14/11.jpg\",\"asset-name\":\"11.jpg\",\"asset-type\":\"image/jpeg\",\"type\":\"asset\",\"class-name\":\"embedded-asset\",\"width\":25.16914749661705,\"className\":\"dsd\",\"id\":\"sdf\"},\"children\":[{\"text\":\"\"}]}],\"type\":\"doc\"}";
4346
public const string kEntryReferenceBlockJson = "{ \"uid\":\"06e34a7 5e4 e549d \", \"_version\":1, \"attrs\":{ }, \"children\":[{\"uid\":\"70f9b 325075d43 128c0d0 aa3eb7f291f\",\"type\":\"reference\",\"attrs\":{\"display-type\":\"block\",\"entry-uid\":\"UID_07\",\"content-type-uid\":\"content_block\",\"locale\":\"en-us\",\"type\":\"entry\",\"class-name\":\"embedded-entry\"},\"children\":[{\"text\":\"\"}]}],\"type\":\"doc\"}";

Contentstack.Utils.Tests/Contentstack.Utils.Tests.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
12-
<PackageReference Include="xunit" Version="2.4.0" />
13-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" >
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
12+
<PackageReference Include="xunit" Version="2.4.2" />
13+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
1414
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1515
<PrivateAssets>all</PrivateAssets>
1616
</PackageReference>
17-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
18-
<PackageReference Include="coverlet.collector" Version="3.0.3">
17+
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
18+
<PackageReference Include="coverlet.collector" Version="3.2.0">
1919
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2020
<PrivateAssets>all</PrivateAssets>
2121
</PackageReference>

Contentstack.Utils.Tests/DefaultRenderTest.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ public void testEmbedDocument()
197197
Assert.Equal($"<iframe src=\"\">{text}</iframe>", result);
198198
}
199199

200+
[Fact]
201+
public void testFragmentDocument()
202+
{
203+
string result = defaultRender.RenderNode("fragment", node, (nodes) => { return text; });
204+
205+
Assert.Equal($"<fragment>{text}</fragment>", result);
206+
}
207+
200208
[Fact]
201209
public void testH1Document()
202210
{

Contentstack.Utils.Tests/JsonToHtmlTest.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,26 @@ public void Should_Return_Result_For_Link_Document()
170170
Assert.Equal(JsonToHtmlResultConstants.kLinkInPHtml, result);
171171
}
172172

173+
[Fact]
174+
public void Should_Return_Result_For_Link_MailTo_Document()
175+
{
176+
Node node = NodeParser.parse(JsonToHtmlConstants.kLinkInPMailToJson);
177+
178+
string result = Utils.JsonToHtml(node, defaultRender);
179+
180+
Assert.Equal(JsonToHtmlResultConstants.kLinkInPMailToHtml, result);
181+
}
182+
183+
[Fact]
184+
public void Should_Return_Result_For_Link_MailTo_Document_Custom()
185+
{
186+
Node node = NodeParser.parse(JsonToHtmlConstants.kLinkInPMailToJson);
187+
188+
string result = Utils.JsonToHtml(node, new CustomRenderOptionMock(null));
189+
190+
Assert.Equal(JsonToHtmlResultConstants.kLinkInPMailToTARGEtHtml, result);
191+
}
192+
173193
[Fact]
174194
public void Should_Return_Result_For_Array_Link_Document()
175195
{

Contentstack.Utils.Tests/Mocks/CustomRenderOptionMock.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ public class CustomRenderOptionMock : Options
1010
public CustomRenderOptionMock(IEntryEmbedable entry) : base(entry)
1111
{
1212
}
13+
public override string RenderNode(string nodeType, Node node, NodeChildrenCallBack callBack)
14+
{
15+
switch (nodeType)
16+
{
17+
case "a":
18+
if (node.attrs.ContainsKey("target"))
19+
{
20+
return $"<a href=\"{(string)node.attrs["url"]}\" target=\"{(string)node.attrs["target"]}\">{callBack(node.children)}</a>";
21+
}
22+
return $"<a href=\"{(string)node.attrs["url"]}\">{callBack(node.children)}</a>";
23+
}
24+
return base.RenderNode(nodeType, node, callBack);
25+
}
26+
1327
public override string RenderOption(IEmbeddedObject embeddedObject, Metadata metadata)
1428
{
1529
var attributeStringList = new List<string>();

Contentstack.Utils/Contentstack.Utils.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<Folder Include="Converters\" />
3939
</ItemGroup>
4040
<ItemGroup>
41-
<PackageReference Include="HtmlAgilityPack" Version="1.11.28" />
42-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
41+
<PackageReference Include="HtmlAgilityPack" Version="1.11.46" />
42+
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
4343
</ItemGroup>
4444
</Project>

Contentstack.Utils/Models/Options.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ public virtual string RenderNode(string nodeType, Node node, NodeChildrenCallBac
135135
href = (string)node.attrs["url"];
136136
}
137137
return $"<iframe{styleAttrs} src=\"{href}\">{callBack(node.children)}</iframe>";
138+
case "fragment":
139+
return $"<fragment{styleAttrs}>{callBack(node.children)}</fragment>";
138140
case "h1":
139141
return $"<h1{styleAttrs}>{callBack(node.children)}</h1>";
140142
case "h2":

SECURITY.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## Security
2+
3+
Contentstack takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations.
4+
5+
If you believe you have found a security vulnerability in any Contentstack-owned repository, please report it to us as described below.
6+
7+
## Reporting Security Issues
8+
9+
**Please do not report security vulnerabilities through public GitHub issues.**
10+
11+
Send email to [security@contentstack.com](mailto:security@contentstack.com).
12+
13+
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message.
14+
15+
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
16+
17+
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
18+
* Full paths of source file(s) related to the manifestation of the issue
19+
* The location of the affected source code (tag/branch/commit or direct URL)
20+
* Any special configuration required to reproduce the issue
21+
* Step-by-step instructions to reproduce the issue
22+
* Proof-of-concept or exploit code (if possible)
23+
* Impact of the issue, including how an attacker might exploit the issue
24+
25+
This information will help us triage your report more quickly.
26+
27+
[https://www.contentstack.com/trust/](https://www.contentstack.com/trust/)

0 commit comments

Comments
 (0)