ngx-markdown icon indicating copy to clipboard operation
ngx-markdown copied to clipboard

How to compile Markdown file included as link?

Open kmikurda opened this issue 1 year ago • 2 comments

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?

kmikurda avatar Jun 15 '23 12:06 kmikurda

I have the same question. Does anybody have a solution or a workaround? Thanks

lee3morris avatar Nov 15 '23 17:11 lee3morris

Likely you want to do a few things:

  1. update your routes to take a :slug or similar based on the URL
  2. update your initial component to take this :slug from the URL and parse it to the specific path to the .md file
  3. 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>

NateRadebaugh avatar Nov 17 '23 02:11 NateRadebaugh