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
@@ -14,19 +15,21 @@ namespace Markdig.Parsers.Inlines;
1415/// <seealso cref="InlineParser" />
1516public class AutolinkInlineParser : InlineParser
1617{
18+ public AutolinkInlineParser ( ) : this ( new AutolinkOptions ( ) )
19+ {
20+
21+ }
22+
1723 /// <summary>
1824 /// Initializes a new instance of the <see cref="AutolinkInlineParser"/> class.
1925 /// </summary>
20- public AutolinkInlineParser ( )
26+ public AutolinkInlineParser ( AutolinkOptions options )
2127 {
28+ Options = options ?? throw new ArgumentNullException ( nameof ( options ) ) ;
2229 OpeningCharacters = [ '<' ] ;
23- EnableHtmlParsing = true ;
2430 }
2531
26- /// <summary>
27- /// Gets or sets a value indicating whether to enable HTML parsing. Default is <c>true</c>
28- /// </summary>
29- public bool EnableHtmlParsing { get ; set ; }
32+ public readonly AutolinkOptions Options ;
3033
3134 public override bool Match ( InlineProcessor processor , ref StringSlice slice )
3235 {
@@ -42,8 +45,12 @@ public override bool Match(InlineProcessor processor, ref StringSlice slice)
4245 Line = line ,
4346 Column = column
4447 } ;
48+ if ( Options . OpenInNewWindow )
49+ {
50+ processor . Inline . GetAttributes ( ) . AddPropertyIfNotExist ( "target" , "_blank" ) ;
51+ }
4552 }
46- else if ( EnableHtmlParsing )
53+ else if ( Options . EnableHtmlParsing )
4754 {
4855 slice = saved ;
4956 if ( ! HtmlHelper . TryParseHtmlTag ( ref slice , out string ? htmlTag ) )
@@ -57,6 +64,10 @@ public override bool Match(InlineProcessor processor, ref StringSlice slice)
5764 Line = line ,
5865 Column = column
5966 } ;
67+ if ( Options . OpenInNewWindow )
68+ {
69+ processor . Inline . GetAttributes ( ) . AddPropertyIfNotExist ( "target" , "_blank" ) ;
70+ }
6071 }
6172 else
6273 {
0 commit comments