Open Crono1981 opened 6 years ago
Thanks for reporting the issue. @willemduncan when you have a chance can you respond? I didn't see CDATA anywhere in the docs https://docs.microsoft.com/en-us/dotnet/csharp/codedoc so perhaps its best to find a different way to flag those comments (e.g. by their <code>
element or I know the easiest one is to remove the leading space).
Is there a way I could possibly help? Test something?
Thanks for offering to help. @willemduncan anything you could advise?
CData does not automatically mean we should interpret literally, it is just an XML hint.
In an XML document or external parsed entity, a CDATA section is a section of element content that is marked for the parser to interpret purely as textual data, not as markup. (from Wikipedia)
The <code>
block however, should be interpreted literally instead of parsed. I think the combination of the two might cause an issue here. Try removing the <![CDATA[ .... ]]>
and see what happens? What's the reason for including that anyway?
@willemduncan in my example, removing CDATA
will result in badly formed XML for the comment, because of this line:
/// class Foo : IComparable<Foo>
It will complain about an unclosed Foo
element.
Of course I could encode the line this way:
/// class Foo : IComparable$lt;Foo>
I however find that to be quite a pain in the a** to have to do so. Especially if you plan on having lots of examples in your doc.
Likewise, any code making use of greater than / lower than operators will also have this issue.
I've found this MSDN blog post from 2006 (!) that mentions using CDATA
to encapsulate example code segments:
https://blogs.msdn.microsoft.com/ansonh/2006/09/11/c-xml-documentation-comments-faq/
Whoah that is some arcane C# 1.0 documentation you dug up there 👍 The issue with gt/lt getting encoded is known, see #561. I'll add 'CDATA' support to the requirements list.
I've tried some approaches for getting both these issues fixed, but it's harder than expected. The formatting code uses XElement
to parse the text, which automatically encodes the XML special chars when writing output. There is a WriteRaw
method which can fix this, but then I got into issues with your CDATA blocks. It's decending so deep into XML handling that it might be better just to drop native XML parsing altogether... but I'm open for suggestions.
Just so we're clear: I don't expect CodeMaid tidying up my code example as it does with regular code. :)
I just feel that CDATA objects found within code comments should be ignored and remain untouched. Even if they do happen to have long lines or stuff like that. For all I care, CodeMaid may replace a CDATA block with an empty string, do its comment tidying up routine and then just put back the unaltered CDATA blocks at the expected positions.
I don't know how other users might feel about this but I would find it quite okay that CodeMaid can't "fix" CDATA blocks. Seems totally fair.
At the moment your CDATA block is inside a <code>
block and will not (OK, should not) be touched at all. It's definitely not parsed as code ;) The problem is with the XML reader/writer used to format the comment that the code is part of. It treats CDATA different, and causes the current problems with whitespace disappearing.
I can second this issue, but for ANY HTML tag in your comments. It is useful to be able to use a <see cref="...">
, etc. in the summary comments.
The good news is, it doesn't seem to affect how it renders in the tools.
That is just a line break in the XML tag, works as intended. Look for the setting "Keep XML tags together" to control this behavior.
That is just a line break in the XML tag, works as intended. Look for the setting "Keep XML tags together" to control this behavior.
Thank you!
Cheers!
Any update to this? I'm also experiencing issues with CodeMaid reformatting some comments that are contained within CDATA. I've got two different classes where I use this and in one it will reformat incorrectly while in the other it leaves the comment alone as is. I've tried looking and I don't see any difference between the files.
Environment
Description
Suppose you have the following xml documentation comments on a method:
Upon running CodeMaid with the format comments option on, it will rewrite the doc like this:
As you can see, indentation has been removed and the whole thing just looks ugly.
I think that whatever is found within a CDATA element should remain untouched, regardless of the format comments setting.