File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
src/Markdig/Parsers/Inlines Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+ using System . Text ;
5+ using System . Threading . Tasks ;
6+
7+ namespace Markdig . Parsers . Inlines ;
8+
9+ public class LinkInlineOptions
10+ {
11+ /// <summary>
12+ /// Should the link open in a new window when clicked (false by default)
13+ /// </summary>
14+ public bool OpenInNewWindow { get ; set ; }
15+ }
Original file line number Diff line number Diff line change 33// See the license.txt file in the project root for more information.
44
55using Markdig . Helpers ;
6+ using Markdig . Renderers . Html ;
67using Markdig . Syntax ;
78using Markdig . Syntax . Inlines ;
89
@@ -17,11 +18,22 @@ public class LinkInlineParser : InlineParser
1718 /// <summary>
1819 /// Initializes a new instance of the <see cref="LinkInlineParser"/> class.
1920 /// </summary>
20- public LinkInlineParser ( )
21+ public LinkInlineParser ( ) : this ( new LinkInlineOptions ( ) )
2122 {
23+
24+ }
25+
26+ /// <summary>
27+ /// Initializes a new instance of the <see cref="LinkInlineParser"/> class.
28+ /// </summary>
29+ public LinkInlineParser ( LinkInlineOptions options )
30+ {
31+ Options = options ?? throw new ArgumentNullException ( nameof ( options ) ) ;
2232 OpeningCharacters = [ '[' , ']' , '!' ] ;
2333 }
2434
35+ public readonly LinkInlineOptions Options ;
36+
2537 public override bool Match ( InlineProcessor processor , ref StringSlice slice )
2638 {
2739 // The following methods are inspired by the "An algorithm for parsing nested emphasis and links"
@@ -169,6 +181,11 @@ private bool ProcessLinkReference(
169181 linkInline . LocalLabel = localLabel ;
170182 }
171183
184+ if ( Options . OpenInNewWindow )
185+ {
186+ linkInline . GetAttributes ( ) . AddPropertyIfNotExist ( "target" , "_blank" ) ;
187+ }
188+
172189 link = linkInline ;
173190 }
174191
You can’t perform that action at this time.
0 commit comments