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

Open all links in a new window/tab? #432

Closed
RudeySH opened this issue May 7, 2020 · 1 comment
Closed

Open all links in a new window/tab? #432

RudeySH opened this issue May 7, 2020 · 1 comment

Comments

@RudeySH
Copy link
Contributor

RudeySH commented May 7, 2020

#327 added AutoLinkOptions with OpenInNewWindow. How can this be applied for all links, not just auto-links?

@RudeySH
Copy link
Contributor Author

RudeySH commented May 7, 2020

Oh, figured it out.

var document = Markdown.Parse(markdown, pipeline);

foreach (var descendant in document.Descendants())
{
	if (descendant is AutolinkInline || descendant is LinkInline)
	{
		descendant.GetAttributes().AddPropertyIfNotExist("target", "_blank");
	}
}

using var writer = new StringWriter();
var renderer = new HtmlRenderer(writer);
pipeline.Setup(renderer);
renderer.Render(document);

var html = writer.ToString();

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

1 participant