The FilterHtml method processes a string containing HTML
formatted text, removes the markup and returns output suitable for display
in text-only environments. HTML tags are removed and entities are
converted to their canonical Unicode equivalent. When filtering markup
from the text, the method will:
- Remove all leading and trailing whitespace from the text,
including newlines.
- Remove script, style, and other non-visible or unsafe elements.
- Convert common tag structures, such as lists and headers, into readable plain text.
- Extract and filter hyperlinks and image alt text, ignoring
internal links to other sections.
- Remove any embedded credentials in hyperlinks.
- Decode common HTML entities such as
&trade and
©, as well as numeric entites like  .
The method will remove extraneous whitespace within the text, but will
attempt to maintain the structure of ordered and unordered lists. It does
not parse the style information or Javascript that may be included in the
HTML content. If a paragraph uses a style that would normally prevent it from
being rendered in a browser (e.g.: the visibility attribute set to "hidden"),
it is ignored and the text will be included in the output. If there
are sections which contain preformatted text, such as text inside
<pre>...</pre> or <code>...</code>
tags, individual line and paragraph breaks will be preserved.
If you are concerned that the HTML may contain obfuscated text or
confusable Unicode homoglyphs, you can pass the output from this method to
the FilterUnicode method. However, you should not do this if the
original HTML content includes non-Latin characters or symbols because it
can cause the text to become unreadable. For example, if the HTML content
contains Greek text, those characters may be corrupted during the text
normalization process that decomposes the Unicode characters and replaces
homoglyphs with standard representations of those characters.
If the HTML text passed to this method includes any entities which are represented as
Unicode, such as ½ which represents "½",
they will be returned in the output string buffer as Unicode characters.
This method will not strip Unicode characters from the input text. If you
are using this control in Visual Basic, this could result in characters
which cannot be displayed by the standard controls such as Label
or TextBox. These controls attempt to convert Unicode to ANSI
using the system locale, which can result in garbled or missing characters.
To correctly display full Unicode text, you must use controls that support
Unicode natively, such as those in the Microsoft Forms 2.0 Object Library (FM20.DLL)
with appropriate font settings, or render the text using Windows API
functions.