Skip to content

Commit

Permalink
Remove unnecessary para tags which appear as the single element of a …
Browse files Browse the repository at this point in the history
…<summary> element
  • Loading branch information
sharwell committed Feb 6, 2015
1 parent ccaab49 commit 44eac36
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,22 @@ private async Task<Document> CreateChangedDocument(CodeFixContext context, Docum
private SyntaxNode MarkUnnecessaryParagraphs(SyntaxNode originalNode, SyntaxNode rewrittenNode)
{
XmlElementSyntax elementSyntax = rewrittenNode as XmlElementSyntax;
if (!IsUnnecessaryParaElement(elementSyntax))
return rewrittenNode;
if (IsUnnecessaryParaElement(elementSyntax))
return elementSyntax.WithAdditionalAnnotations(UnnecessaryParagraphAnnotation);

if (string.Equals("summary", elementSyntax?.StartTag?.Name?.ToString(), StringComparison.Ordinal))
{
SyntaxList<XmlNodeSyntax> trimmedContent = elementSyntax.Content.WithoutFirstAndLastNewlines();
if (trimmedContent.Count == 1
&& IsParaElement(trimmedContent[0] as XmlElementSyntax)
&& !HasAttributes(trimmedContent[0] as XmlElementSyntax))
{
XmlNodeSyntax paraToRemove = elementSyntax.Content.GetFirstXmlElement("para");
return elementSyntax.ReplaceNode(paraToRemove, paraToRemove.WithAdditionalAnnotations(UnnecessaryParagraphAnnotation));
}
}

return elementSyntax.WithAdditionalAnnotations(UnnecessaryParagraphAnnotation);
return rewrittenNode;
}

private SyntaxNode RemoveUnnecessaryParagraphs(XmlElementSyntax originalNode, XmlElementSyntax rewrittenNode)
Expand Down Expand Up @@ -203,7 +215,7 @@ private static bool HasLooseContent(SyntaxList<XmlNodeSyntax> content)

private static bool HasAttributes(XmlElementSyntax syntax)
{
return syntax.StartTag?.Attributes.Count > 0;
return syntax?.StartTag?.Attributes.Count > 0;
}

private static bool IsParaElement(XmlElementSyntax syntax)
Expand Down

0 comments on commit 44eac36

Please sign in to comment.