| |
| INT GetFilteredText( |
| |
LPTSTR lpszFilteredText, |
|
| |
INT nMaxLength |
|
| ); |
The GetFilteredText method filters HTML formatting
from the current document and returns plain text in a string buffer.
Parameters
- lpszFilteredText
- A null-terminated string buffer which will contain the filtered
text. If this parameter is NULL and the nMaxLength parameter
is zero, the method will return the number of characters required
to store the filtered text, not including the terminating null
character.
- nMaxLength
- The maximum number of characters which can be copied into the
lpszFilteredText string buffer. If this value is zero, no
characters will be copied to the buffer and the method will
return the length of the filtered text, not including the
terminating null character. This can be used to determine how much
memory should be allocated for the string.
Return Value
If the method succeeds, it will return the number of characters
copied into the string buffer, not including the terminating null
character. If the lpszFilteredText parameter is NULL and nMaxLength
is zero, the method will return the number of characters in the
filtered text without copying any characters. If the method
fails, or there is no text in the input buffer, the method will
return zero. To get extended error information, call
GetLastError.
Remarks
The GetFilteredText method filters the HTML markup from the
document text 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 entities 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.
This method will not remove Unicode characters from the input
text. If the HTML markup includes any entities which are represented as
Unicode, such as ½ which represents "½",
they will be returned in the output string buffer as Unicode characters.
If the ANSI version of this method is called, Unicode will always be
returned as UTF-8 encoded characters.
Example
INT nLength = pWebView->GetFilteredText(NULL, 0);
if (nLength > 0)
{
LPTSTR pszFiltered = (LPTSTR)malloc((nLength + 1) * sizeof(TCHAR));
if (!pszFiltered )
{
return;
}
nLength = pWebView->GetFilteredText(pszFiltered, nLength + 1);
if (nLength > 0)
{
_putts(pszFiltered);
}
free(pszFiltered);
}
Requirements
Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: cshtmv12.lib
Unicode: Implemented as Unicode and ANSI versions
See Also
|
|