Skip to content

Commit

Permalink
Clicking link in comment opens in new tab (#8060)
Browse files Browse the repository at this point in the history
* Added comments open in new tab functionality, testing needed

* Open comment link in new tab complete

* Corrected program.cs
  • Loading branch information
WhitShake authored Apr 10, 2024
1 parent b4ffdd2 commit 3b5c840
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/dotnet/APIView/APIViewWeb/CommentMarkdownExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public static IHtmlContent FormatAsMarkdown(this IHtmlHelper helper, string text
{
try
{
return new HtmlString(MarkdownAsHtml(text));
string htmlContent = MarkdownAsHtml(text);
htmlContent = AddTargetBlankToLinks(htmlContent);
return new HtmlString(htmlContent);
}
catch
{
Expand All @@ -31,5 +33,10 @@ public static string MarkdownAsHtml(string text) =>

public static string MarkdownAsPlainText(string text) =>
Markdown.ToPlainText(text ?? "", MarkdownPipeline);

private static string AddTargetBlankToLinks(string htmlContent)
{
return System.Text.RegularExpressions.Regex.Replace(htmlContent, "<a(?!.*?target=)(.*?)>", "<a$1 target=\"_blank\" rel=\"noopener noreferrer\">");
}
}
}
4 changes: 2 additions & 2 deletions src/dotnet/APIView/APIViewWeb/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.AddEnvironmentVariables(prefix: "APIVIEW_");
config.AddUserSecrets(typeof(Program).Assembly);
config.AddEnvironmentVariables(prefix: "APIVIEW_");
IConfiguration settings = config.Build();
string connectionString = settings.GetValue<string>("APPCONFIG");
// Load configuration from Azure App Configuration
Expand All @@ -28,6 +27,7 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
kv.SetCredential(new DefaultAzureCredential());
});
});
config.AddUserSecrets(typeof(Program).Assembly);
})
.UseStartup<Startup>();
}
Expand Down

0 comments on commit 3b5c840

Please sign in to comment.