Search code examples
html.netcommentsdocumentation

Including HTML markup in code examples when using .NET code documentation XML


.NET has a specific XML syntax for documenting the code.

The <c></c> and <code></code> tags allow to add code snippets into the comments, but apprently, they don't work well when those code snippets are made of HTML, which is a problem, because I would like to document the HTML markup output of my function.

For example, if I write the following (VB) documentation comment :

''' <summary>
''' <code>
''' <div class="foo">Hello world</div>
''' </code>
''' </summary>

It does display the "Hello world" string when I hover the function's name with my pointer, but does not show the HTML markup as is. It seems to be interpreting it instead.

Is there a way to display HTML markup as is within those comments ?

Just to be clear, I'm not trying to add styling to the documentation, I really want it to display the HTML markup itself.


Solution

  • Use CDATA:

    ''' <summary>
    ''' <code><![CDATA[
    ''' <div class="foo">Hello world</div>
    ''' ]]></code>
    ''' </summary>
    

    For example, my product VSdocman has the comment editor which puts CDATA in <code> blocks automatically.