WebApi帮助页面:不要在XML文档中转义HTML [英] WebApi Help Page: don't escape HTML in XML documentation

查看:124
本文介绍了WebApi帮助页面:不要在XML文档中转义HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将XML文档用于ASP.NET Web API帮助页面如此处所示. 我想知道是否有一种方法可以在评论中包含html,以便将其呈现在网页上,而不是将其删除/忽略/转义.
具体来说,我正在寻找一种创建换行符的方法,但是能够创建项目符号列表等会很棒!

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 rendered on the web page, instead of it being removed/ignored/escaped.
Specifically, I am looking for a way to create a newline, but being able to create bulleted lists, etc. would be great!

Ex/我希望能够执行以下操作:

Ex/ I would like to be able to do something like this:

/// <summary>
/// CRUD operations for SalesDocument<br/>
/// This is a new line
/// </summary>
[RoutePrefix("api/SalesDocument")]
public partial class SalesDocumentController : ApiController

将其显示在帮助页面上,如下所示:

And have it show on the help page like this:

CRUD operations for SalesDocument 
This is a new line.

代替这个:(在这种情况下,<br/>会以某种方式被删除-如果我尝试使用<p>标记,它们只会被转义)

Instead of this: (in this case, <br/> gets removed somehow - if I try using <p> tags, they are just escaped)

CRUD operations for SalesDocument This is a new line.

*我已经尝试过<para>标签,如多条提示所建议的那样,但这在我的帮助页面上不起作用.

*I have already tried the <para> tag as suggested by multiple posts for tooltips, but this does not work on my help page.

任何建议都将不胜感激!

Any suggestions are greatly appreciated!

推荐答案

Areas\HelpPage处已安装的XmlDocumentationProvider.cs文件中,您可以查找称为GetTagValue的方法.在这里,将返回值从node.Value.Trim()修改为node.InnerXml.

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;
}

现在打开已安装的文件Areas\HelpPage\Views\Help\DisplayTemplates\ApiGroup.cshtml,并从以下位置修改以下行:

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

<p>@controllerDocumentation</p>

<p>@Html.Raw(controllerDocumentation)</p>

这篇关于WebApi帮助页面:不要在XML文档中转义HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆