Converts HTML content into plain text, used to build search index text, plain-text email bodies and notification snippets from HTML pages, comments and file resources. Strips tags, collapses non-breaking spaces to ordinary spaces, inserts a blank line between block-level elements, and renders link text with its href shown in angle brackets. It is intentionally approximate rather than a full HTML-to-text renderer.
Group: Managers
Methods
generateTextFromHtml(String html)
Returns: String
Converts an HTML fragment into plain text by parsing it and stripping tags, collapsing non-breaking spaces and unescaping HTML entities. The conversion is approximate rather than a faithful rendering. Returns an empty string if the input is null, and returns null if parsing the HTML fails.
| Parameter | Description |
|---|---|
html | the HTML markup to convert, may be null |
getText(List<Resource> list)
Returns: String
Builds a single plain-text document from a list of resources, appending each resource's title or name followed by its rendered body text in turn. Recurses into collection resources to include their children. This is an expensive operation since it visits every resource and, for HTML-bearing resources, parses their body content.
| Parameter | Description |
|---|---|
list | the resources to extract text from, in the order they should appear |
getText(Resource r)
Returns: String
Builds a plain-text representation of a single resource: its title or name followed by its rendered body text if it has one. Recurses into a collection resource to include the text of its children. This is an expensive operation since it may parse HTML body content.
| Parameter | Description |
|---|---|
r | the resource to extract text from |