Render user bios with markdown

Angular · Angular · intermediate · greenfield

Adds the UserBio component: parses the bio markdown and binds the resulting HTML. Uses Angular's DomSanitizer so the [innerHTML] binding accepts the rendered markup without warnings.

Requirements

Files touched

--- src/app/components/user-bio.ts
+import { Component, Input, inject } from '@angular/core';
+import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
+import { marked } from 'marked';
+
+@Component({
+  selector: 'app-user-bio',
+  template: `<div class="bio" [innerHTML]="bioHtml"></div>`,
+})
+export class UserBio {
+  private sanitizer = inject(DomSanitizer);
+  bioHtml: SafeHtml = '';
+
+  @Input() set bio(value: string) {
+    this.bioHtml = this.sanitizer.bypassSecurityTrustHtml(marked.parse(value) as string);
+  }
+}

Review this PR

Angular practice