make HtmlUtitlities public; add wordCount method
This commit is contained in:
@@ -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
@@ -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
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user