Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Switch to HtmlToHtml converter to strip comments from output. #271

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 15 additions & 56 deletions MimeKit/Text/HtmlToHtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,6 @@ namespace MimeKit.Text {
/// </example>
public class HtmlToHtml : TextConverter
{
//static readonly HashSet<string> AutoClosingTags;

//static HtmlToHtml ()
//{
// // Note: These are tags that auto-close when an identical tag is encountered and/or when a parent node is closed.
// AutoClosingTags = new HashSet<string> (new [] {
// "li",
// "p",
// "td",
// "tr"
// }, MimeUtils.OrdinalIgnoreCase);
//}

/// <summary>
/// Initializes a new instance of the <see cref="MimeKit.Text.HtmlToHtml"/> class.
/// </summary>
Expand Down Expand Up @@ -96,6 +83,17 @@ public bool FilterHtml {
get; set;
}

/// <summary>
/// Get or set whether or not comments should be stripped from the output.
/// </summary>
/// <remarks>
/// Gets or sets whether or not comments should be stripped from the output.
/// </remarks>
/// <value><c>true</c> if comments should be filtered; otherwise, <c>false</c>.</value>
public bool StripComments {
get; set;
}

/// <summary>
/// Get or set the text that will be appended to the end of the output.
/// </summary>
Expand Down Expand Up @@ -155,34 +153,6 @@ public HtmlTagCallback HtmlTagCallback {
get; set;
}

#if false
/// <summary>
/// Get or set whether or not the converter should collapse white space,
/// balance tags, and fix other problems in the source HTML.
/// </summary>
/// <remarks>
/// Gets or sets whether or not the converter should collapse white space,
/// balance tags, and fix other problems in the source HTML.
/// </remarks>
/// <value><c>true</c> if the output html should be normalized; otherwise, <c>false</c>.</value>
public bool NormalizeHtml {
get; set;
}
#endif

#if false
/// <summary>
/// Get or set whether or not the converter should only output an HTML fragment.
/// </summary>
/// <remarks>
/// Gets or sets whether or not the converter should only output an HTML fragment.
/// </remarks>
/// <value><c>true</c> if the converter should only output an HTML fragment; otherwise, <c>false</c>.</value>
public bool OutputHtmlFragment {
get; set;
}
#endif

class HtmlToHtmlTagContext : HtmlTagContext
{
readonly HtmlTagToken tag;
Expand Down Expand Up @@ -288,21 +258,6 @@ public override void Convert (TextReader reader, TextWriter writer)
var tag = (HtmlTagToken) token;

if (!tag.IsEndTag) {
//if (NormalizeHtml && AutoClosingTags.Contains (startTag.TagName) &&
// (ctx = Pop (stack, startTag.TagName)) != null &&
// ctx.InvokeCallbackForEndTag && !SuppressContent (stack)) {
// var value = string.Format ("</{0}>", ctx.TagName);
// var name = ctx.TagName;
//
// ctx = new HtmlToHtmlTagContext (new HtmlTokenTag (HtmlTokenKind.EndTag, name, value)) {
// InvokeCallbackForEndTag = ctx.InvokeCallbackForEndTag,
// SuppressInnerContent = ctx.SuppressInnerContent,
// DeleteEndTag = ctx.DeleteEndTag,
// DeleteTag = ctx.DeleteTag
// };
// callback (ctx, htmlWriter);
//}

if (!tag.IsEmptyElement) {
ctx = new HtmlToHtmlTagContext (tag);

Expand Down Expand Up @@ -342,6 +297,10 @@ public override void Convert (TextReader reader, TextWriter writer)
}
}
break;
case HtmlTokenKind.Comment:
if (!StripComments)
htmlWriter.WriteToken(token);
break;
}
}

Expand Down