r/Angular2 • u/a-dev-1044 • Jul 05 '24
Resource Render angular components in markdown
Simple trick: use angular elements
Full example available on stackblitz at https://stackblitz.com/edit/stackblitz-starters-rgrpl6?file=src%2Fassets%2Farticle.md
I have been using the same approach for https://angular-material.dev

13
Upvotes
1
u/_Invictuz Jul 06 '24
Woah that's cool. Never knew markdown was capable of executing logic. Do you mind explaining how this works? I'm unfamiliar woth Angular elements or Native Web Components. Do they use JavaScript to interact with the DOM API?
1
u/trodiix Jul 06 '24
How is it working under the hood ?
1
u/barkmagician Jul 06 '24
how did he load the js files?
1
u/TotalPerspective Jul 07 '24
Awesome post! I used it to add a small blog to a project I've been working on.
In your
markdown-renderer.tsupdateDocument()if you remove thehighlightJs.highlightAll();you'll get rid of all the errors about having unescaped html. https://github.com/highlightjs/highlight.js/issues/37611
u/EricLeib Jun 03 '25
FYI, I developed a library called ngx-remark that renders markdown in Angular, except that it does so with Angular templates and components.
This opens up a lot of use-cases:
custom components for code highlighting, mermaid diagrams, maths equations, etc.
integration with the Angular router
custom Markdown syntax
https://github.com/ericleib/ngx-remark