Skip to content

Commit

Permalink
Add ignoring block quotes in posts
Browse files Browse the repository at this point in the history
  • Loading branch information
ktos committed Dec 9, 2019
1 parent b847b71 commit eefc445
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/HtmlCleaner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ public static string RemoveProperCode(string postText)
return postText;
}

/// <summary>
/// Removes quotations, which should be ignored
/// </summary>
/// <param name="postText">Post content to be cleaned (in HTML)</param>
/// <returns>Post content with Blockquote elements removed</returns>
public static string RemoveQuotes(string postText)
{
postText = Regex.Replace(postText, "<blockquote>(.|\n)*?</blockquote>", "", RegexOptions.Multiline);
return postText;
}

/// <summary>
/// Removes links to downloading attachements
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/PostAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private NotFormattedCodeFound CheckForUnformattedCode(CoyoteApi.Post post)
{
var text = HtmlCleaner.RemoveProperCode(post.text);
text = HtmlCleaner.RemoveDownloadLinks(text);
text = HtmlCleaner.RemoveQuotes(text);

foreach (var para in text.Split("</p>").Select(CleanParagraph))
{
Expand Down
10 changes: 10 additions & 0 deletions test/HtmlCleanerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ public void RemoveDownloadLinks_PostWithDownloadLinks_LinksRemoved()
Assert.Equal("<li>test3", result);
}

[Fact]
public void RemoveQuotes_PostWithQuotes_QuotesRemoved()
{
string postText = "<blockquote>cytat</blockquote>nie cytat<blockquote>cytat</blockquote>";

var result = HtmlCleaner.RemoveQuotes(postText);

Assert.Equal("nie cytat", result);
}

[Fact]
public void StripTags_TextWithTags_TagsRemoved()
{
Expand Down

0 comments on commit eefc445

Please sign in to comment.