mirror of
https://github.com/xoofx/markdig.git
synced 2026-02-10 21:40:00 +00:00
target _blank for absolute urls. #266
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @TerribleDev on GitHub (Jan 21, 2019).
Hi, first off thanks for making this awesome package.
I'm using this for a blog engine I am writing. I have relative and absolute urls. I'd like my absolute urls to render with target="_blank" so they open in a new page.
I know this is a pluggable system, is there some docs for writing plugins? Side note, do you think this would be valuable to contribute back? Would you be interested in such an extension in this repo?
@MihaZupan commented on GitHub (Jan 21, 2019):
I think the easiest way to go about doing this is to parse to the abstract syntax tree (Parse instead of ToHtml), go over all children and call SetAttributes for links with absolute urls.
Markdown object types you're probably interested in would be LinkInline and AutoLinkInline.
@TerribleDev commented on GitHub (Jan 22, 2019):
Hi @MihaZupan thanks so much for your comment.
I understand I need to walk over the AST and add a property. After looking around at the extensions that already exist I came up with this gist which seems to work.
Does that look like the right way to do this?
@MihaZupan commented on GitHub (Jan 22, 2019):
Yep, that looks okay. I've shortened it a bit: gist.
Note that I also added AutoLinkInline, so you handle
<link>cases as well.With that, all versions should be handeled:
@MihaZupan commented on GitHub (Jan 22, 2019):
What I was referring to in the previous comment was editing the AST directly, not through an extension:
That's up to personal preference tho
@TerribleDev commented on GitHub (Jan 27, 2019):
oh ok thanks again for the info!