WebApi Help Page: don't escape HTML in XML documentation

后端 未结 2 640
甜味超标
甜味超标 2020-12-05 11:05

I am using XML Documentation for my ASP.NET Web API Help Page as shown here. I would like to know if there is a way to include html in the comments such that it will be rend

相关标签:
2条回答
  • 2020-12-05 11:28

    In the installed XmlDocumentationProvider.cs file at Areas\HelpPage, you can look for a method called GetTagValue. Here modify the return value from node.Value.Trim() to node.InnerXml.

    private static string GetTagValue(XPathNavigator parentNode, string tagName)
    {
        if (parentNode != null)
        {
            XPathNavigator node = parentNode.SelectSingleNode(tagName);
            if (node != null)
            {
                return node.InnerXml; 
            } 
        }
    
        return null;
    }
    

    Now open the installed file Areas\HelpPage\Views\Help\DisplayTemplates\ApiGroup.cshtml and modify the following line from:

    <p>@controllerDocumentation</p>
    

    to

    <p>@Html.Raw(controllerDocumentation)</p>
    
    0 讨论(0)
  • 2020-12-05 11:38

    @controllerDocumentation does not work for me, but changing the line to@api.Documentation works. i.e. @html.raw(api.Documentation).

    0 讨论(0)
提交回复
热议问题