Skip to content
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
33 changes: 0 additions & 33 deletions .github/workflows/ci.yml

This file was deleted.

45 changes: 45 additions & 0 deletions .github/workflows/nuget-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This workflow will publish a package when a release is created

name: Publish package to NuGet repository
on:
release:
types: [created]
jobs:
publish-nuget:
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v1
- name: Setup .NET Core @ Latest
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.x'
env:
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_AUTH_TOKEN }}
- name: Build solution and generate NuGet package
run: |
cd contentstack-utils-dotnet
dotnet pack -c Release -o out

- name: Push generated package to GitHub registry
run: dotnet nuget push ./contentstack-utils-dotnet/out/*.nupkg --api-key $NUGET_AUTH_TOKEN --skip-duplicate --no-symbols true

publish-git:
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v1
- name: Setup .NET Core @ Latest
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.x'
source-url: https://nuget.pkg.github.com/Contentstack/index.json
env:
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build solution and generate NuGet package
run: |
cd contentstack-utils-dotnet
dotnet pack -c Release -o out

- name: Push generated package to GitHub registry
run: dotnet nuget push ./contentstack-utils-dotnet/out/*.nupkg --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate --no-symbols true
11 changes: 0 additions & 11 deletions .github/workflows/sast-scan.yml

This file was deleted.

12 changes: 8 additions & 4 deletions .github/workflows/sca-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ jobs:
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Checkout repository
uses: actions/checkout@master
- uses: snyk/actions/setup@master
- name: Setup .NET
uses: actions/[email protected]
- name: Restore dependencies
run: dotnet restore ./Contentstack.Utils.sln
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/dotnet@master
run: cd Contentstack.Utils && snyk test --fail-on=all
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --fail-on=all
11 changes: 0 additions & 11 deletions .github/workflows/secrets-scan.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fileignoreconfig:
- filename: Contentstack.Utils/Models/Options.cs
checksum: 3dc51f0de02429ef9a43b66e666ac4dbde41195e245f8ecc0094548ca8603245
version: ""
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.2
#### Date: Mar-14-2024
- Style attributes supported in converted HTML.

### Version: 1.0.1
#### Date: July-16-2021
- Json RTE content to Html Support added.
Expand Down
4 changes: 2 additions & 2 deletions Contentstack.Utils.Tests/Constants/JsonToHtmlConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static class JsonToHtmlResultConstants
{
public const string kPlainTextHtml = "<strong>Aliquam sit amet libero dapibus, eleifend ligula at, varius justo</strong><strong><em>Lorem ipsum</em></strong><strong><em><u>dolor sit amet</u></em></strong><strong><em><u><strike>consectetur adipiscing elit.</strike></u></em></strong><strong><em><u><span>Sed condimentum iaculis magna in vehicula. </span></u></em></strong><strong><em><u><sup> Vestibulum vitae convallis </sup></u></em></strong><strong><em><u><sub> lacus. </sub></u></em></strong>";
public const string kParagraphHtml = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed condimentum iaculis magna in vehicula. Vestibulum vitae convallis lacus. Praesent a diam iaculis turpis rhoncus faucibus. Aliquam sed pulvinar sem.</p>";
public const string kH1Html = "<h1><strong><em><u><sub>Lorem ipsum dolor sit amet.</sub></u></em></strong></h1>";
public const string kH1Html = "<h1 style=\"color: blue; font-size: 24px;\"><strong><em><u><sub>Lorem ipsum dolor sit amet.</sub></u></em></strong></h1>";
public const string kH2Html = "<h2><strong><em><u><sub>Vestibulum a ligula eget massa sagittis aliquam sit amet quis tortor. </sub></u></em></strong></h2>";
public const string kH3Html = "<h3><strong><em><u><sub>Mauris venenatis dui id massa sollicitudin, non bibendum nunc dictum.</sub></u></em></strong></h3>";
public const string kH4Html = "<h4><strong><em><u><sub>MaNullam feugiat turpis quis elit interdum, vitae laoreet quam viverra</sub></u></em></strong></h4>";
Expand All @@ -24,7 +24,7 @@ public static class JsonToHtmlConstants
{
public const string kBlankDocument = "{ \"uid\":\"06e34a7a4e5d7fc2acd\", \"_version\":13, \"attrs\":{ }, \"children\":[],\"type\":\"doc\"}";
public const string kPlainTextJson = "{ \"uid\":\"06e34a7a4e5d7fc2acd\", \"_version\":13, \"attrs\":{ }, \"children\":[{\"text\":\"Aliquam sit amet libero dapibus, eleifend ligula at, varius justo\",\"bold\":true},{ \"text\":\"Lorem ipsum\",\"bold\":true,\"italic\":true},{ \"text\":\"dolor sit amet\",\"bold\":true,\"italic\":true,\"underline\":true},{ \"text\":\"consectetur adipiscing elit.\",\"bold\":true,\"italic\":true,\"underline\":true,\"strikethrough\":true},{ \"text\":\"Sed condimentum iaculis magna in vehicula. \",\"bold\":true,\"italic\":true,\"underline\":true,\"inlineCode\":true},{ \"text\":\" Vestibulum vitae convallis \",\"bold\":true,\"italic\":true,\"underline\":true,\"superscript\":true},{ \"text\":\" lacus. \",\"bold\":true,\"italic\":true,\"underline\":true,\"subscript\":true}],\"type\":\"doc\"}";
public const string kH1Json = "{ \"uid\":\"06e34a7a449d7fc2acd\",\"_version\":13,\"attrs\":{ },\"children\":[{ \"type\":\"h1\",\"attrs\":{ },\"uid\":\"c2dfed70 4d7030c65e2e1\",\"children\":[{ \"text\":\"Lorem ipsum dolor sit amet.\",\"bold\":true,\"italic\":true,\"underline\":true,\"subscript\":true}]}],\"type\":\"doc\"}";
public const string kH1Json = "{ \"uid\":\"06e34a7a449d7fc2acd\",\"_version\":13,\"attrs\":{ },\"children\":[{ \"type\":\"h1\",\"attrs\":{ \"style\": { \"color\": \"blue\", \"font-size\": \"24px\" } },\"uid\":\"c2dfed70 4d7030c65e2e1\",\"children\":[{ \"text\":\"Lorem ipsum dolor sit amet.\",\"bold\":true,\"italic\":true,\"underline\":true,\"subscript\":true}]}],\"type\":\"doc\"}";
public const string kH2Json = "{ \"uid\":\"06e34a7a4e2acd\",\"_version\":13,\"attrs\":{ },\"children\":[{ \"type\":\"h2\",\"attrs\":{ },\"uid\":\"c2dfed9a7030c65e2e1\",\"children\":[{ \"text\":\"Vestibulum a ligula eget massa sagittis aliquam sit amet quis tortor. \",\"bold\":true,\"italic\":true,\"underline\":true,\"subscript\":true}]}],\"type\":\"doc\"}";
public const string kH3Json = "{ \"uid\":\"06e34ad7fc2acd\",\"_version\":13,\"attrs\":{ },\"children\":[{ \"type\":\"h3\",\"attrs\":{ },\"uid\":\"c2df42cfb70 4d7030c65e2e1\",\"children\":[{ \"text\":\"Mauris venenatis dui id massa sollicitudin, non bibendum nunc dictum.\",\"bold\":true,\"italic\":true,\"underline\":true,\"subscript\":true}]}],\"type\":\"doc\"}";
public const string kH4Json = "{ \"uid\":\"06e34a7a4e54cd\", \"_version\":13, \"attrs\":{ \"style\":{ \"text-align\":\"center\" }, \"redactor-attributes\":{ } }, \"children\":[{\"type\":\"h4\",\"attrs\":{},\"uid\":\"c2dfed4d7030c65e2e1\",\"children\":[{\"text\":\"MaNullam feugiat turpis quis elit interdum, vitae laoreet quam viverra\",\"bold\":true,\"italic\":true,\"underline\":true,\"subscript\":true}]}],\"type\":\"doc\"}";
Expand Down
15 changes: 11 additions & 4 deletions Contentstack.Utils.Tests/Contentstack.Utils.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFrameworks>netstandard2.0;net47;net472;</TargetFrameworks>

<IsPackable>false</IsPackable>
<ReleaseVersion>1.0.1</ReleaseVersion>
<ReleaseVersion>$(Version)</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" >
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="coverlet.collector" Version="3.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<Reference Include="Contentstack.Utils">
<HintPath>..\Contentstack.Utils\bin\Debug\netstandard2.0\Contentstack.Utils.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Contentstack.Utils\Contentstack.Utils.csproj" />
</ItemGroup>
Expand Down
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.1
version = 1.0.2
Policies = $0
$0.DotNetNamingPolicy = $1
$1.DirectoryNamespaceAssociation = PrefixedHierarchical
Expand Down
6 changes: 3 additions & 3 deletions Contentstack.Utils/Contentstack.Utils.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
<Authors>Contentstack</Authors>
<NeutralLanguage>en-US</NeutralLanguage>
<Description>Utils .NET SDK for the Contentstack.</Description> <ReleaseVersion>0.1.0</ReleaseVersion>
<PackageVersion>1.0.1</PackageVersion>
<PackageVersion>$(Version)</PackageVersion>
<Owners>Contentstack</Owners>
<PackOnBuild>true</PackOnBuild>
<PackageTags>v1.0.1</PackageTags>
<PackageTags>v$(Version)</PackageTags>
<PackageReleaseNotes>Json RTE content to Html content support added</PackageReleaseNotes>
<Copyright>Copyright © 2012-2021 Contentstack. All Rights Reserved</Copyright>
<PackageProjectUrl>https://github.com/contentstack/contentstack-utils-dotnet</PackageProjectUrl>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<ReleaseVersion>1.0.1</ReleaseVersion>
<ReleaseVersion>$(Version)</ReleaseVersion>
<Title>Contentstack Utils</Title>
</PropertyGroup>

Expand Down
66 changes: 45 additions & 21 deletions Contentstack.Utils/Models/Options.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Contentstack.Utils.Enums;
using Contentstack.Utils.Interfaces;

Expand Down Expand Up @@ -89,66 +90,89 @@ public virtual string RenderMark(MarkType markType, string text)
public virtual string RenderNode(string nodeType, Node node, NodeChildrenCallBack callBack)
{
string href = "";
string styleAttrs = "";

if (node.attrs.ContainsKey("style"))
{
var styleVal = node.attrs["style"];
if (styleVal != null)
{
if (styleVal is string)
{
styleAttrs = $" style=\"{styleVal}\"";
}
else if (styleVal is IDictionary<string, string>)
{
var styleDictionary = (IDictionary<string, string>)styleVal;
styleAttrs = " style=\"";
foreach (var pair in styleDictionary)
{
styleAttrs += $"{pair.Key}:{pair.Value};";
}
styleAttrs += "\"";
}
}
}
switch (nodeType)
{
case "p":
return $"<p>{callBack(node.children)}</p>";
return $"<p{styleAttrs}>{callBack(node.children)}</p>";
case "a":
if (node.attrs.ContainsKey("url"))
{
href = (string)node.attrs["url"];
}
return $"<a href=\"{href}\">{callBack(node.children)}</a>";
return $"<a href=\"{href}\"{styleAttrs}>{callBack(node.children)}</a>";
case "img":
if (node.attrs.ContainsKey("url"))
{
href = (string)node.attrs["url"];
}
return $"<img src=\"{href}\" />{callBack(node.children)}";
return $"<img{styleAttrs} src=\"{href}\" />{callBack(node.children)}";
case "embed":
if (node.attrs.ContainsKey("url"))
{
href = (string)node.attrs["url"];
}
return $"<iframe src=\"{href}\">{callBack(node.children)}</iframe>";
return $"<iframe{styleAttrs} src=\"{href}\">{callBack(node.children)}</iframe>";
case "h1":
return $"<h1>{callBack(node.children)}</h1>";
return $"<h1{styleAttrs}>{callBack(node.children)}</h1>";
case "h2":
return $"<h2>{callBack(node.children)}</h2>";
return $"<h2{styleAttrs}>{callBack(node.children)}</h2>";
case "h3":
return $"<h3>{callBack(node.children)}</h3>";
return $"<h3{styleAttrs}>{callBack(node.children)}</h3>";
case "h4":
return $"<h4>{callBack(node.children)}</h4>";
return $"<h4{styleAttrs}>{callBack(node.children)}</h4>";
case "h5":
return $"<h5>{callBack(node.children)}</h5>";
return $"<h5{styleAttrs}>{callBack(node.children)}</h5>";
case "h6":
return $"<h6>{callBack(node.children)}</h6>";
return $"<h6{styleAttrs}>{callBack(node.children)}</h6>";
case "ol":
return $"<ol>{callBack(node.children)}</ol>";
return $"<ol{styleAttrs}>{callBack(node.children)}</ol>";
case "ul":
return $"<ul>{callBack(node.children)}</ul>";
return $"<ul{styleAttrs}>{callBack(node.children)}</ul>";
case "li":
return $"<li>{callBack(node.children)}</li>";
return $"<li{styleAttrs}>{callBack(node.children)}</li>";
case "hr":
return $"<hr>";
case "table":
return $"<table>{callBack(node.children)}</table>";
return $"<table{styleAttrs}>{callBack(node.children)}</table>";
case "thead":
return $"<thead>{callBack(node.children)}</thead>";
return $"<thead{styleAttrs}>{callBack(node.children)}</thead>";
case "tbody":
return $"<tbody>{callBack(node.children)}</tbody>";
return $"<tbody{styleAttrs}>{callBack(node.children)}</tbody>";
case "tfoot":
return $"<tfoot>{callBack(node.children)}</tfoot>";
return $"<tfoot{styleAttrs}>{callBack(node.children)}</tfoot>";
case "tr":
return $"<tr>{callBack(node.children)}</tr>";
return $"<tr{styleAttrs}>{callBack(node.children)}</tr>";
case "th":
return $"<th>{callBack(node.children)}</th>";
return $"<th{styleAttrs}>{callBack(node.children)}</th>";
case "td":
return $"<td>{callBack(node.children)}</td>";
return $"<td{styleAttrs}>{callBack(node.children)}</td>";
case "blockquote":
return $"<blockquote>{callBack(node.children)}</blockquote>";
case "code":
return $"<code>{callBack(node.children)}</code>";
return $"<code{styleAttrs}>{callBack(node.children)}</code>";
default:
return callBack(node.children);
}
Expand Down
5 changes: 5 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<Version>1.0.2</Version>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright © 2012-2021 Contentstack. All Rights Reserved
Copyright © 2012-2024 Contentstack. All Rights Reserved

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down