Table of Contents

Class HtmlHelperText

Namespace
SunamoHtml.Html
Assembly
SunamoHtml.dll

Helper class for HTML text manipulation (tag replacement, tag parsing, syntax detection, etc.).

public static class HtmlHelperText
Inheritance
HtmlHelperText
Inherited Members

Methods

ContainsTag(string, IList<string>)

Checks if text contains any of the specified HTML tags.

public static bool ContainsTag(string text, IList<string> allHtmlTagsWithLeftArrow)

Parameters

text string

The text to check.

allHtmlTagsWithLeftArrow IList<string>

List of HTML tags to check for (with <).

Returns

bool

True if text contains any of the specified tags.

ConvertTextToHtml(IList<string>)

Converts a list of text lines to HTML with paragraphs.

public static string ConvertTextToHtml(IList<string> lines)

Parameters

lines IList<string>

List of text lines to convert.

Returns

string

HTML string with lines wrapped in paragraphs.

CreateH2FromNumberedList(IList<string>)

Creates H2 tags from numbered list items in the lines.

public static IList<string> CreateH2FromNumberedList(IList<string> lines)

Parameters

lines IList<string>

List of lines to process.

Returns

IList<string>

List with numbered items wrapped in H2 tags.

GetAllEquvivalentsOfNonPairingTag(string)

Gets all equivalent variations of a non-pairing tag.

public static IList<string> GetAllEquvivalentsOfNonPairingTag(string tagName)

Parameters

tagName string

The tag name.

Returns

IList<string>

List of tag variations: <tag>, <tag />, <tag/>.

GetAllTags(string)

Gets all HTML tags from the input using regex.

public static IList<string> GetAllTags(string text)

Parameters

text string

The HTML input string.

Returns

IList<string>

List of all HTML tags found.

GetContentOfTags(string, string)

Gets the content of all occurrences of a specific tag in the text.

public static IList<string> GetContentOfTags(string text, string tagName)

Parameters

text string

The HTML text to search.

tagName string

The tag name to extract content from.

Returns

IList<string>

List of content strings from all found tags.

GetSyntax(ref string)

Gets the syntax type of an HTML tag (paired ended, paired not ended, non-paired).

public static HtmlTagSyntax GetSyntax(ref string tag)

Parameters

tag string

The tag string to analyze (will be modified to clean tag name).

Returns

HtmlTagSyntax

The HTML tag syntax type.

GetTextBetweenTags(string, string, string, bool)

Gets text between HTML tags and extracts tag attributes.

public static Tuple<string, string> GetTextBetweenTags(string html, string scriptS, string scriptE, bool isThrowExceptionIfNotContains = true)

Parameters

html string

The HTML string to search in.

scriptS string

The starting tag.

scriptE string

The ending tag.

isThrowExceptionIfNotContains bool

Whether to throw exception if tags not found.

Returns

Tuple<string, string>

Tuple with text content and attributes string.

InsertMissingEndingTags(string, string)

Inserts missing ending tags for unclosed start tags.

public static string InsertMissingEndingTags(string text, string tag)

Parameters

text string

The HTML text to fix.

tag string

The tag name to check for missing ending tags.

Returns

string

HTML with missing ending tags inserted.

IsCssDeclarationName(string)

Checks if a string is a valid CSS declaration name.

public static bool IsCssDeclarationName(string decl)

Parameters

decl string

The CSS declaration name to check.

Returns

bool

True if it's a valid CSS property name.

IsHtmlEntity(string)

Checks if a string is a valid HTML entity (without & and ;).

public static bool IsHtmlEntity(string text)

Parameters

text string

The text to check.

Returns

bool

True if text is a valid HTML entity name.

RemoveAllNodes(string)

Removes all HTML nodes from the HTML string, leaving only text nodes.

public static string RemoveAllNodes(string htmlText)

Parameters

htmlText string

The HTML string to process.

Returns

string

HTML with all element nodes removed.

RemoveAspxComments(string)

Removes ASP.NET comments from HTML.

public static string RemoveAspxComments(string html)

Parameters

html string

The HTML content.

Returns

string

HTML with ASPX comments removed.

RemoveHtmlTags(string)

Removes all HTML tags from text.

public static string RemoveHtmlTags(string clipboardText)

Parameters

clipboardText string

The text with HTML tags.

Returns

string

Text with all HTML tags and spaces removed.

ReplacePairTag(string, string, string)

Replaces all occurrences of a pair tag with another tag.

public static string ReplacePairTag(string text, string tag, string replacement)

Parameters

text string

The HTML input string.

tag string

The tag to replace.

replacement string

The replacement tag name.

Returns

string

HTML with replaced tags.

SplitBySpaceAndLtGt(string)

Splits text by space and HTML angle brackets.

public static IList<string> SplitBySpaceAndLtGt(string shortDescription)

Parameters

shortDescription string

The text to split.

Returns

IList<string>

List of split segments.

TrimInnerOfEncodedHtml(string)

Trims inner content of HTML-encoded text by adding spaces around > and <.

public static string TrimInnerOfEncodedHtml(string text)

Parameters

text string

The HTML-encoded text.

Returns

string

Text with spaces added around encoded brackets.