Adds HTML to a string to highlight chosen sections.
string
, search: string
, wrapperClass: string
= "highlight"
): HighlightTransformResult
search
string(s) within text
and highlights all occurrences.string
- Text to search withinstring
- Text pattern to search forstring
- CSS class used to provide highlighting styleHighlightTransformResult
- New text along with boolean value to indicate whether anything was highlightedA typical use case for this service is to display the results from a search engine. An excerpt of a retrieved document can be shown with the matching search terms highlighted to indicate where they were found.
The service works by adding HTML <span> elements around all sections of text
that match the search
string. You can specify multiple search strings at once by
separating them with spaces, so passing "Apple Banana Cherry" in search
will
highlight any of those words individually. The <span> element includes a
class
attribute which defaults to "highlight" but you can pass any class name
you like using the wrapperClass
parameter.
The resulting text with HTML highlighting is returned within a HighlightTransformResult
object:
interface HighlightTransformResult { text: string; changed: boolean; }
The changed
flag will be false if the search string was not found (ie, no highlighting
took place) and true otherwise.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.