Skip to content

Commit

Permalink
Adds support for custom text in cref references (dotnet#7979)
Browse files Browse the repository at this point in the history
* Adds support for custom text in cref references

dotnet#7978

* Remove extra line feed

* Remove trailing space

* Remove preserving formatting, since it'll get escaped by the html formatter
  • Loading branch information
dotMorten authored Apr 8, 2022
1 parent b95256b commit ebfd9a6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,15 @@ private void ResolveCrefLink(XNode node, string nodeSelector, Action<string, str
// When see and seealso are top level nodes in triple slash comments, do not convert it into xref node
if (item.Parent?.Parent != null)
{
var replacement = XElement.Parse($"<xref href=\"{HttpUtility.UrlEncode(id)}\" data-throw-if-not-resolved=\"false\"></xref>");
XElement replacement;
if(string.IsNullOrEmpty(item.Value))
{
replacement = XElement.Parse($"<xref href=\"{HttpUtility.UrlEncode(id)}\" data-throw-if-not-resolved=\"false\"></xref>");
}
else
{
replacement = XElement.Parse($"<xref href=\"{HttpUtility.UrlEncode(id)}?text={HttpUtility.UrlEncode(item.Value)}\" data-throw-if-not-resolved=\"false\"></xref>");
}
item.ReplaceWith(replacement);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,51 @@ public int Main(string[] args)
Assert.Equal("http://www.bing.com", seeAlsos[2].LinkId);
}


[Trait("Related", "TripleSlashComments")]
[Fact]
public void SeeAltText()
{
string inputFolder = Path.GetRandomFileName();
Directory.CreateDirectory(inputFolder);
string input = @"
<member name='T:TestClass1.Partial1'>
<summary>
Class summary <see cref='T:System.AccessViolationException'>Exception type</see>
</summary>
<remarks>
See <see cref='T:System.Int'>Integer</see>.
</remarks>
<returns>Returns an <see cref='T:System.AccessViolationException'>Exception</see>.</returns>
<param name='input'>This is an <see cref='T:System.AccessViolationException'>Exception</see>.</param>
</member>";
var context = new TripleSlashCommentParserContext
{
AddReferenceDelegate = null,
PreserveRawInlineComments = false,
Source = new SourceDetail
{
Path = Path.Combine(inputFolder, "Source.cs"),
}
};

var commentModel = TripleSlashCommentModel.CreateModel(input, SyntaxLanguage.CSharp, context);
Assert.True(commentModel.InheritDoc == null, nameof(commentModel.InheritDoc));

var summary = commentModel.Summary;
Assert.Equal("\nClass summary <xref href=\"System.AccessViolationException?text=Exception+type\" data-throw-if-not-resolved=\"false\"></xref>\n", summary);

var returns = commentModel.Returns;
Assert.Equal("Returns an <xref href=\"System.AccessViolationException?text=Exception\" data-throw-if-not-resolved=\"false\"></xref>.", returns);

var paramInput = commentModel.Parameters["input"];
Assert.Equal("This is an <xref href=\"System.AccessViolationException?text=Exception\" data-throw-if-not-resolved=\"false\"></xref>.", paramInput);

var remarks = commentModel.Remarks;
Assert.Equal("\nSee <xref href=\"System.Int?text=Integer\" data-throw-if-not-resolved=\"false\"></xref>.\n", remarks);
}

[Trait("Related", "TripleSlashComments")]
[Fact]
public void InheritDoc()
Expand Down

0 comments on commit ebfd9a6

Please sign in to comment.