diff --git a/ReadSharp/HtmlUtilities.cs b/ReadSharp/HtmlUtilities.cs index 554d254..60911c6 100644 --- a/ReadSharp/HtmlUtilities.cs +++ b/ReadSharp/HtmlUtilities.cs @@ -4,8 +4,13 @@ using System.IO; namespace ReadSharp { - internal class HtmlUtilities + public class HtmlUtilities { + /// + /// Converts HTML to plain text / strips tags. + /// + /// The HTML. + /// public static string ConvertToPlainText(string html) { HtmlDocument doc = new HtmlDocument(); @@ -18,6 +23,18 @@ namespace ReadSharp } + /// + /// Count the words. + /// The content has to be converted to plain text before (using ConvertToPlainText). + /// + /// The plain text. + /// + public static int CountWords(string plainText) + { + return !String.IsNullOrEmpty(plainText) ? plainText.Split(' ', '\n').Length : 0; + } + + public static string Cut(string text, int length) { if (!String.IsNullOrEmpty(text) && text.Length > length) diff --git a/ReadSharp/Reader.cs b/ReadSharp/Reader.cs index 781743e..9d98aed 100644 --- a/ReadSharp/Reader.cs +++ b/ReadSharp/Reader.cs @@ -183,7 +183,7 @@ namespace ReadSharp try { plainContent = HtmlUtilities.ConvertToPlainText(transcodingResult.ExtractedContent); - wordCount = !String.IsNullOrEmpty(plainContent) ? plainContent.Split(' ', '\n').Length : 0; + wordCount = HtmlUtilities.CountWords(plainContent); } catch {