From 042fa5d7d9d36996d338b132fa64965b9315ce45 Mon Sep 17 00:00:00 2001 From: kaso17 Date: Wed, 8 Feb 2017 11:28:44 +0100 Subject: [PATCH] Add ToHtmlPretty for AngleSharp --- src/Jackett/Utils/StringUtil.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Jackett/Utils/StringUtil.cs b/src/Jackett/Utils/StringUtil.cs index 0287b5f6a..14979a600 100644 --- a/src/Jackett/Utils/StringUtil.cs +++ b/src/Jackett/Utils/StringUtil.cs @@ -1,6 +1,9 @@ -using System; +using AngleSharp.Dom; +using AngleSharp.Html; +using System; using System.Collections.Generic; using System.Collections.Specialized; +using System.IO; using System.Linq; using System.Net.Http; using System.Security.Cryptography; @@ -76,6 +79,20 @@ namespace Jackett.Utils return string.Join("&", collection.AllKeys.Select(a => a + "=" + HttpUtility.UrlEncode(collection[a], encoding))); } + public static string ToHtmlPretty(this IElement element) + { + if (element == null) + return ""; + + StringBuilder sb = new StringBuilder(); + StringWriter sw = new StringWriter(sb); + var formatter = new PrettyMarkupFormatter(); + element.ToHtml(sw, formatter); + return sb.ToString(); + } + + + public static string GenerateRandom(int length) { var chars = "abcdefghijklmnopqrstuvwxyz0123456789";