Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to compile Markdown file included as link? #460

Open
kmikurda opened this issue Jun 15, 2023 · 2 comments
Open

How to compile Markdown file included as link? #460

kmikurda opened this issue Jun 15, 2023 · 2 comments

Comments

@kmikurda
Copy 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?

@lee3morris
Copy link

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

@NateRadebaugh
Copy link
Contributor

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants