DataWeb
Search Results for

    Show / Hide Table of Contents

    Class HtmlService

    Provides HTML and SVG sanitization and manipulation services using HtmlSanitizer and regex patterns.

    Inheritance
    object
    HtmlService
    Implements
    IHtmlService
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: DataWeb.Text.Html.AngleSharp
    Assembly: DataWeb.Text.Html.AngleSharp.dll
    Syntax
    public class HtmlService : IHtmlService

    Properties

    Name

    Gets the name that identifies this HTML service provider.

    Declaration
    public string Name { get; }
    Property Value
    Type Description
    string

    Methods

    ConvertToText(string)

    Converts HTML to plain text by removing tags and styles, and converting line breaks to newlines.

    Declaration
    public string ConvertToText(string value)
    Parameters
    Type Name Description
    string value

    The HTML string to convert. Returns unchanged if null or empty.

    Returns
    Type Description
    string

    Plain text extracted from the HTML.

    IsSafeSvg(string)

    Checks if an SVG string contains potentially unsafe content such as scripts or event handlers.

    Declaration
    public bool IsSafeSvg(string value)
    Parameters
    Type Name Description
    string value

    The SVG string to validate. Returns true if null or empty.

    Returns
    Type Description
    bool

    true if the SVG is safe; false if it contains unsafe patterns.

    IsSvg(string)

    Determines whether a string is valid SVG markup by checking for SVG tags and parsing XML structure.

    Declaration
    public bool IsSvg(string value)
    Parameters
    Type Name Description
    string value

    The string to validate as SVG. Returns false if null or empty.

    Returns
    Type Description
    bool

    true if the string is valid SVG; false otherwise.

    RemoveInvalidHtmlTags(string)

    Removes or escapes invalid HTML tags while preserving safe elements like iframes, videos, and media tags.

    Declaration
    public string RemoveInvalidHtmlTags(string value)
    Parameters
    Type Name Description
    string value

    The HTML string to sanitize. Returns unchanged if null or empty.

    Returns
    Type Description
    string

    The sanitized HTML string.

    ReplaceHtmlEntities(string)

    Encodes special HTML characters to their entity equivalents and corrects malformed entities.

    Declaration
    public string ReplaceHtmlEntities(string value)
    Parameters
    Type Name Description
    string value

    The string to encode. Returns unchanged if null or empty.

    Returns
    Type Description
    string

    The HTML-encoded string with <, >, and & properly escaped.

    SanitizeSvg(string)

    Sanitizes SVG content by removing unsafe elements and attributes, preserving only safe SVG graphics tags.

    Declaration
    public string SanitizeSvg(string value)
    Parameters
    Type Name Description
    string value

    The SVG string to sanitize. Returns unchanged if null or empty.

    Returns
    Type Description
    string

    The sanitized SVG string.

    StripHtml(string)

    Removes all HTML tags from the input string, leaving only text content.

    Declaration
    public string StripHtml(string value)
    Parameters
    Type Name Description
    string value

    The HTML string to process. Returns unchanged if null or empty.

    Returns
    Type Description
    string

    The string with all HTML tags removed.

    Implements

    IHtmlService
    In this article
    Back to top Generated by DocFX