in src/app/shared/doc-viewer/doc-viewer.ts [109:128]
private updateDocument(rawDocument: string) {
// Replace all relative fragment URLs with absolute fragment URLs. e.g. "#my-section" becomes
// "/components/button/api#my-section". This is necessary because otherwise these fragment
// links would redirect to "/#my-section".
rawDocument = rawDocument.replace(/href="#([^"]*)"/g, (_m: string, fragmentUrl: string) => {
const absoluteUrl = `${location.pathname}#${fragmentUrl}`;
return `href="${this._domSanitizer.sanitize(SecurityContext.URL, absoluteUrl)}"`;
});
this._elementRef.nativeElement.innerHTML = rawDocument;
this.textContent = this._elementRef.nativeElement.textContent;
this._loadComponents('material-docs-example', ExampleViewer);
this._loadComponents('header-link', HeaderLink);
// Resolving and creating components dynamically in Angular happens synchronously, but since
// we want to emit the output if the components are actually rendered completely, we wait
// until the Angular zone becomes stable.
this._ngZone.onStable
.pipe(take(1))
.subscribe(() => this.contentRendered.next(this._elementRef.nativeElement));
}