Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8271,6 +8271,56 @@ interface IGoo { }
List<string> y = null;
"""));

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/53384")]
public Task TestDocumentationCData2()
=> TestAsync("""
using I$$ = IGoo;
/// <summary>
/// summary for interface IGoo
/// <code><![CDATA[
/// void M()
/// {
/// Console.WriteLine();
/// }
/// ]]></code>
/// </summary>
interface IGoo { }
""",
MainDescription("interface IGoo"),
Documentation("""
summary for interface IGoo

void M()
{
Console.WriteLine();
}
"""));

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/53384")]
public Task TestDocumentationCData3()
=> TestAsync("""
using I$$ = IGoo;
/// <summary>
/// summary for interface IGoo
/// <![CDATA[
/// void M()
/// {
/// Console.WriteLine();
/// }
/// ]]>
/// </summary>
interface IGoo { }
""",
MainDescription("interface IGoo"),
Documentation("""
summary for interface IGoo

void M()
{
Console.WriteLine();
}
"""));

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/37503")]
public Task DoNotNormalizeWhitespaceForCode()
=> TestAsync("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,22 @@ public ImmutableArray<TaggedText> Format(string rawXmlText, ISymbol symbol, Sema

private static void AppendTextFromNode(FormatterState state, XNode node, Compilation compilation)
{
if (node.NodeType is XmlNodeType.Text or XmlNodeType.CDATA)
if (node is XText textNode)
{
// cast is safe since XCData inherits XText
AppendTextFromTextNode(state, (XText)node);
if (textNode.NodeType == XmlNodeType.Text)
{
AppendTextFromTextNode(state, textNode);
}
else if (textNode.NodeType == XmlNodeType.CDATA)
{
state.PushStyle(TaggedTextStyle.Code | TaggedTextStyle.PreserveWhitespace);
state.MarkBeginOrEndPara();
AppendTextFromTextNode(state, textNode);
state.MarkBeginOrEndPara();
state.PopStyle();
}

return;
}

if (node.NodeType != XmlNodeType.Element)
Expand Down Expand Up @@ -402,8 +414,8 @@ DocumentationCommentXmlNames.SeeAlsoElementName or
state.NextListItem();
}

if (name is DocumentationCommentXmlNames.ParaElementName
or DocumentationCommentXmlNames.CodeElementName)
if (name is DocumentationCommentXmlNames.ParaElementName or
DocumentationCommentXmlNames.CodeElementName)
{
state.MarkBeginOrEndPara();
}
Expand All @@ -417,8 +429,8 @@ DocumentationCommentXmlNames.SeeAlsoElementName or
AppendTextFromNode(state, childNode, compilation);
}

if (name is DocumentationCommentXmlNames.ParaElementName
or DocumentationCommentXmlNames.CodeElementName)
if (name is DocumentationCommentXmlNames.ParaElementName or
DocumentationCommentXmlNames.CodeElementName)
{
state.MarkBeginOrEndPara();
}
Expand Down
Loading