make HtmlUtitlities public; add wordCount method

This commit is contained in:
2014-01-30 11:23:29 +01:00
parent 1b91582025
commit 122ccfe7b6
2 changed files with 19 additions and 2 deletions
+18 -1
View File
@@ -4,8 +4,13 @@ using System.IO;
namespace ReadSharp namespace ReadSharp
{ {
internal class HtmlUtilities public class HtmlUtilities
{ {
/// <summary>
/// Converts HTML to plain text / strips tags.
/// </summary>
/// <param name="html">The HTML.</param>
/// <returns></returns>
public static string ConvertToPlainText(string html) public static string ConvertToPlainText(string html)
{ {
HtmlDocument doc = new HtmlDocument(); HtmlDocument doc = new HtmlDocument();
@@ -18,6 +23,18 @@ namespace ReadSharp
} }
/// <summary>
/// Count the words.
/// The content has to be converted to plain text before (using ConvertToPlainText).
/// </summary>
/// <param name="plainText">The plain text.</param>
/// <returns></returns>
public static int CountWords(string plainText)
{
return !String.IsNullOrEmpty(plainText) ? plainText.Split(' ', '\n').Length : 0;
}
public static string Cut(string text, int length) public static string Cut(string text, int length)
{ {
if (!String.IsNullOrEmpty(text) && text.Length > length) if (!String.IsNullOrEmpty(text) && text.Length > length)
+1 -1
View File
@@ -183,7 +183,7 @@ namespace ReadSharp
try try
{ {
plainContent = HtmlUtilities.ConvertToPlainText(transcodingResult.ExtractedContent); plainContent = HtmlUtilities.ConvertToPlainText(transcodingResult.ExtractedContent);
wordCount = !String.IsNullOrEmpty(plainContent) ? plainContent.Split(' ', '\n').Length : 0; wordCount = HtmlUtilities.CountWords(plainContent);
} }
catch catch
{ {