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
textstringThe text to check.
allHtmlTagsWithLeftArrowIList<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
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
Returns
GetAllEquvivalentsOfNonPairingTag(string)
Gets all equivalent variations of a non-pairing tag.
public static IList<string> GetAllEquvivalentsOfNonPairingTag(string tagName)
Parameters
tagNamestringThe tag name.
Returns
GetAllTags(string)
Gets all HTML tags from the input using regex.
public static IList<string> GetAllTags(string text)
Parameters
textstringThe HTML input string.
Returns
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
Returns
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
tagstringThe 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
htmlstringThe HTML string to search in.
scriptSstringThe starting tag.
scriptEstringThe ending tag.
isThrowExceptionIfNotContainsboolWhether to throw exception if tags not found.
Returns
InsertMissingEndingTags(string, string)
Inserts missing ending tags for unclosed start tags.
public static string InsertMissingEndingTags(string text, string tag)
Parameters
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
declstringThe 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
textstringThe 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
htmlTextstringThe 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
htmlstringThe HTML content.
Returns
- string
HTML with ASPX comments removed.
RemoveHtmlTags(string)
Removes all HTML tags from text.
public static string RemoveHtmlTags(string clipboardText)
Parameters
clipboardTextstringThe 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
textstringThe HTML input string.
tagstringThe tag to replace.
replacementstringThe 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
shortDescriptionstringThe text to split.
Returns
TrimInnerOfEncodedHtml(string)
Trims inner content of HTML-encoded text by adding spaces around > and <.
public static string TrimInnerOfEncodedHtml(string text)
Parameters
textstringThe HTML-encoded text.
Returns
- string
Text with spaces added around encoded brackets.