MCPcopy Create free account
hub / github.com/angular/angular / parseLabelToHtml

Method parseLabelToHtml

adev/shared-docs/services/search.service.ts:167–187  ·  view source on GitHub ↗

* Returns an HTML string with marked text for the matches

(label: string | null)

Source from the content-addressed store, hash-verified

165 * Returns an HTML string with marked text for the matches
166 */
167 private parseLabelToHtml(label: string | null): string | null {
168 if (label === null) {
169 return null;
170 }
171
172 const parts: Array<{highlight: boolean; text: string}> = [];
173 while (label.indexOf('<ɵ>') !== -1) {
174 const beforeMatch = label.substring(0, label.indexOf('<ɵ>'));
175 const match = label.substring(label.indexOf('<ɵ>') + 3, label.indexOf('</ɵ>'));
176 parts.push({highlight: false, text: beforeMatch});
177 parts.push({highlight: true, text: match});
178 label = label.substring(label.indexOf('</ɵ>') + 4);
179 }
180 parts.push({highlight: false, text: label});
181
182 return parts
183 .map((part) => {
184 return part.highlight ? `<mark>${part.text}</mark>` : `<span>${part.text}</span>`;
185 })
186 .join('');
187 }
188
189 public searchWithQuery(query: string): Promise<SearchResultItem[] | undefined> {
190 return this.client

Callers 1

parseResultMethod · 0.95

Calls 4

indexOfMethod · 0.80
mapMethod · 0.80
joinMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected