import { Component, Input, OnChanges, OnInit } from '@angular/core';
import DOMPurify from 'dompurify';
import { marked } from 'marked';

@Component({
  selector: 'app-markdown',
  imports: [],
  standalone: true,
  templateUrl: './markdown.component.html',
})
export class MarkdownComponent implements OnChanges {
  @Input() markdown: string = '';
  innerHTML: string = '';

  async parseMD() {
    this.innerHTML = DOMPurify.sanitize(await marked.parse(this.markdown));
  }

  ngOnChanges(): void {
    this.parseMD();
  }
}
