ngx-markdown
ngx-markdown copied to clipboard
How to compile Markdown file included as link?
Hi,
I have one .md-parent file and several .md-children files.
In the component, I compile the parent file:
async ngOnInit() { const markdownRaw = wait for it.http.get('./assets/docs/index.md', { response type: 'text' }).toPromise(); this.markdown = this.mdService.compile(markdownRaw!); }
And it works fine.
in the parent Markdown file, I have links to sub files. e.g.:
* [Orders](./assets/docs/Orders/orders.md).
If I click on that link, I'm redirected to the link provided, but the file is displayed as plain text.
What should I do to compile these sub files?
I have the same question. Does anybody have a solution or a workaround? Thanks
Likely you want to do a few things:
- update your routes to take a :slug or similar based on the URL
- update your initial component to take this :slug from the URL and parse it to the specific path to the
.md
file - Update the
renderer
for.link
and parse out if it's a link to a.md
file, and if so, you can safely strip out the./assets/
portion of the URL so that it navigates to the component as defined in your routes in 1. above
To simplify things even further, you can avoid performing your http requests yourself and instead rely on the built-in functionality documented here: https://jfcere.github.io/ngx-markdown/get-started#usage
<markdown [src]="'./assets/' + slug"></markdown>