in src/Sarif.Viewer.VisualStudio.Core/SdkUiUtilities.cs [611:681]
private static List<XamlDoc.Inline> GetMessageInlinesHelper(string message, RoutedEventHandler clickHandler)
{
var inlines = new List<XamlDoc.Inline>();
MatchCollection matches = Regex.Matches(message, EmbeddedLinkPattern, RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace);
int start = 0;
if (matches.Count > 0)
{
Group group = null;
foreach (Match match in matches)
{
group = match.Groups["text"];
// Add the plain text segment between the end of the last group and the current link.
inlines.Add(new XamlDoc.Run(UnescapeBrackets(message.Substring(start, group.Index - 1 - start))));
object target = null;
if (clickHandler != null)
{
string targetText = match.Groups["target"].Value;
int id;
if (int.TryParse(targetText, out id))
{
target = id;
}
else if (Uri.TryCreate(targetText, UriKind.Absolute, out Uri uri))
{
// This is super dangerous! We are launching URIs for SARIF logs
// that can point to anything.
// https://github.com/microsoft/sarif-visualstudio-extension/issues/171
target = uri;
}
if (target != null)
{
var link = new XamlDoc.Hyperlink
{
// Stash the id of the target location. This is used in SarifSnapshot.ErrorListInlineLink_Click.
Tag = target,
};
// Set the hyperlink text
link.Inlines.Add(new XamlDoc.Run($"{group.Value}"));
link.Click += clickHandler;
inlines.Add(link);
}
}
if (target == null)
{
// Either we don't have a click handler, or the target text wasn't a valid int or Uri.
// Add the link text as plain text.
inlines.Add(new XamlDoc.Run($"{group.Value}"));
}
start = match.Index + match.Length;
}
}
if (inlines.Count > 0 && start < message.Length)
{
// Add the plain text segment after the last link
inlines.Add(new XamlDoc.Run(UnescapeBrackets(message.Substring(start))));
}
return inlines;
}