Angularize the output markdown input for the purpose of links
See original GitHub issueWe are creating a knowledge base using markdown and would like to be able to navigate between the different pages using markdown links.
I want to be able to do like: [click this link](routerlink#./other%20document.md)
or something like that and have it render as <a [routerLink]="['./other document.md']">click this link</a>
I can do that using the renderer, but Angular doesn’t pick up the routerLink and bootstrap it. The link is unclickable.
This means that when I click links, the entire application reloads instead of using SPA routing.
Is there a way to do what I’m trying to do here? Can my documentation writers create links in our markdown documents?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:31
- Comments:23 (3 by maintainers)
Top Results From Across the Web
Markdown to HTML to Angular Components at Runtime
Generating HTML from Markdown at runtime is a great way to load content, but the generated HTML sits outside of the the Angular...
Read more >Rendering Markdown In Angular - Medium
How to use Angular directives to render markdown documents ... a navigate output emitting the url string when the user click on a...
Read more >Using markdown-parser in Angular - Stack Overflow
i am using this markdown-parser in my angular6 app. on giving input # markdown-it rulezz!, **hi** the expected output is it would be ......
Read more >ngx-markdown | Demo
To add ngx-markdown library to your package.json use the following commands. ... any string and specify the prefix using the filterOutput input property....
Read more >Embedding Links - Markdown Monster Documentation
Using inline text linking (ctrl-shift-k); Using raw Markdown Syntax; Using raw HTML Syntax. The Paste Link Dialog (ctrl-k). You can use the Link...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi fellas,
I just want you guys to know that this will be my next priority when I’ll get some time to work on the library (which is pretty hard these days).
In the meanwhile, if any of you want to jump into the wagon, please feel free to contribute as this might not be an easy one!
Thanks for understanding.
Hi fellas,
Working on the new demo for ngx-markdown I stumbled across this issue. I red workaround propositions and did some reverse-engineering with angular
routerLink
directive and came up with creating a dedicated service.This is not an official solution that is integrated to ngx-markdown yet but this is something I am considering (unless Ivy solves the problem in a more fashionable way).
For anybody who end up here, I’d like you to give it a try and comment on how was the integration, if you had issues or any possible improvements that could benefit all of us.
AnchorService
I’ve created an
AnchorService
to centralize all the logic around manipulating generated links from markdown.RouterModule configuration
The following
RouterModule
configuration is required to enabled anchors be scrolled to when URL has a fragment via the Angular router:app-routing.module.ts
Intercept link click event
This is where the magic happens! Using
HostListener
wiithdocument:click
event, it is possible to intercept theclick
event on any HTML element.Doing so in the
AppComponent
to callAnchorService.interceptClick(event: Event)
will useRouter.navigate()
to navigate if the following conditions are alltrue
:HTMLAnchorElement
href
value of the element is an internal linkrouterLink
directiveapp.component.ts
Landing directly on a page with fragment (hash)
To be able to scroll to an element when loading the application for the first time when there is a fragment (#hash) in the URL you can call
AnchorService.scrollToAnchor()
when the content of the DOM is available and markdown have been parsed.Fix generated
href
pathIn order to fix the link URLs for the case where somebody would want to use the “copy link adress” context menu option of the browser, you can override the
link
token usingMarkedRenderer
when importingMarkdownModule
throughmarkedOptions
configuration property.By calling
AnchorService.normalizeExternalUrl(url)
and passing the result tourl
parameter to the original prototype function, it will reuses the originallink
token generation function and have the correcthref
value without rewritting the function.app.module.ts