using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace Smakolykytl2Epub.Utils; public class Content { public string type { get; set; } public List marks { get; set; } public string text { get; set; } } public class Mark { public string type { get; set; } } public class TextJson { public string type { get; set; } public List content { get; set; } } public class HtmlConverter { public static string ConvertJsonToHtml(string json) { var token = JToken.Parse(json); return ConvertTokenToHtml(token); } private static string ConvertTokenToHtml(JToken token) { var html = ""; if (token is JArray) { foreach (var childToken in token.Children()) html += ConvertTokenToHtml(childToken); } else if (token is JObject) { var text = JsonConvert.DeserializeObject(token.ToString()); for (int i = 0; i < text?.content?.Count; i++) { Content str = text.content[i]; if (str != null) { html += str.text; } if (str.type == "hardBreak") { html += "
"; } if (str.type == "paragraph") { html += "

"; } } html += "
"; } else { html += token.ToString(); } return html; } }