WebApi 帮助页面:不要在 XML 文档中转义 HTML [英] WebApi Help Page: don't escape HTML in XML documentation
问题描述
我的 ASP.NET Web API 帮助页面使用 XML 文档 如下所示.我想知道是否有办法在评论中包含 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/ 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.
*我已经按照多篇工具提示帖子的建议尝试了
标签,但这在我的帮助页面上不起作用.
*I have already tried the <para>
tag as suggested by multiple posts for tooltips, but this does not work on my help page.
非常感谢任何建议!
推荐答案
在 AreasHelpPage
安装的 XmlDocumentationProvider.cs
文件中,您可以查找一个名为GetTagValue
.这里将返回值从node.Value.Trim()
修改为node.InnerXml
.
In the installed XmlDocumentationProvider.cs
file at AreasHelpPage
, 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;
}
现在打开已安装的文件AreasHelpPageViewsHelpDisplayTemplatesApiGroup.cshtml
并修改以下行:
Now open the installed file AreasHelpPageViewsHelpDisplayTemplatesApiGroup.cshtml
and modify the following line from:
<p>@controllerDocumentation</p>
到
<p>@Html.Raw(controllerDocumentation)</p>
这篇关于WebApi 帮助页面:不要在 XML 文档中转义 HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!