44using Contentstack . Utils . Extensions ;
55using Contentstack . Utils . Interfaces ;
66using System ;
7+ using Contentstack . Utils . Enums ;
78
89namespace Contentstack . Utils
910{
1011 public class Utils
1112 {
13+ public static List < string > RenderContent ( List < string > contents , Options options )
14+ {
15+ List < string > result = new List < string > ( ) ;
16+
17+ contents . ForEach ( ( content ) =>
18+ {
19+ result . Add ( RenderContent ( content , options ) ) ;
20+ } ) ;
21+
22+ return result ;
23+ }
24+
1225 public static string RenderContent ( string content , Options options )
1326 {
1427 HtmlDocument htmlDocument = new HtmlDocument ( ) ;
@@ -29,18 +42,74 @@ public static string RenderContent(string content, Options options)
2942 return resultContent ;
3043 }
3144
32- public static List < string > RenderContent ( List < string > contents , Options options )
45+ public static List < string > JsonToHtml ( List < Node > nodes , Options options )
3346 {
47+
3448 List < string > result = new List < string > ( ) ;
3549
36- contents . ForEach ( ( content ) =>
50+ nodes . ForEach ( ( node ) =>
3751 {
38- result . Add ( RenderContent ( content , options ) ) ;
52+ result . Add ( JsonToHtml ( node , options ) ) ;
3953 } ) ;
4054
4155 return result ;
4256 }
4357
58+ public static string JsonToHtml ( Node node , Options options )
59+ {
60+ return nodeChildrenToHtml ( node . children , options ) ;
61+ }
62+
63+ private static string nodeChildrenToHtml ( List < Node > nodes , Options options )
64+ {
65+ return string . Join ( "" , nodes . ConvertAll < string > ( node => nodeToHtml ( node , options ) ) ) ;
66+
67+ }
68+
69+ private static string nodeToHtml ( Node node , Options options )
70+ {
71+ switch ( node . type )
72+ {
73+ case Enums . NodeType . Text :
74+ return textToHtml ( ( TextNode ) node , options ) ;
75+ }
76+ return "" ;
77+ }
78+
79+ private static string textToHtml ( TextNode textNode , Options options )
80+ {
81+ var text = textNode . text ;
82+ if ( textNode . superscript )
83+ {
84+ text = options . RenderMark ( MarkType . Superscript , text : text ) ;
85+ }
86+ if ( textNode . subscript )
87+ {
88+ text = options . RenderMark ( MarkType . Subscript , text : text ) ;
89+ }
90+ if ( textNode . inlineCode )
91+ {
92+ text = options . RenderMark ( MarkType . InlineCode , text : text ) ;
93+ }
94+ if ( textNode . strikethrough )
95+ {
96+ text = options . RenderMark ( MarkType . Strikethrough , text : text ) ;
97+ }
98+ if ( textNode . underline )
99+ {
100+ text = options . RenderMark ( MarkType . Underline , text : text ) ;
101+ }
102+ if ( textNode . italic )
103+ {
104+ text = options . RenderMark ( MarkType . Italic , text : text ) ;
105+ }
106+ if ( textNode . bold )
107+ {
108+ text = options . RenderMark ( MarkType . Bold , text : text ) ;
109+ }
110+ return text ;
111+ }
112+
44113 private static IEmbeddedObject findEmbeddedObject ( Metadata metadata , IEntryEmbedable entryEmbedable )
45114 {
46115
0 commit comments