[英]ASP.NET Web API Help Page with markdown comments
I use asp.net WebApi Help Page to generate the document from comments of source code. 我使用asp.net WebApi帮助页面从源代码的注释生成文档。 And I have used doxygen to generate the document before.
而且我以前曾使用doxygen生成文档。 The doxygen can parse markdown syntax in the comments and output the well formatted documents.
doxygen可以解析注释中的markdown语法并输出格式正确的文档。 But the WebApi Help Page could not parse markdown syntax now.
但是, WebApi帮助页面现在无法解析markdown语法。
For example, the foo
function's comments contain Markdown comments , and it will be output as ### Markdown comments *It will return "foo" *It always returns "foo"
in WebApi Help Page . 例如,
foo
函数的注释包含Markdown注释 ,它将作为### Markdown comments *It will return "foo" *It always returns "foo"
输出### Markdown comments *It will return "foo" *It always returns "foo"
在WebApi帮助页面中 ### Markdown comments *It will return "foo" *It always returns "foo"
。
public MyApiController : ApiController {
///<summary>
/// It will return "foo"
/// ### Markdown comments
/// * It will return "foo"
/// * It always returns "foo"
///</summary>
[HttpPost, ActionName("foo")]
public string Foo() {
return "foo";
}
}
Thanks for the hints, have just modified HelpPageApiModel.cshtml
感谢您的提示,刚刚修改了
HelpPageApiModel.cshtml
1) Install some Markdown library from NuGet, like MarkdownDeep
1)从NuGet安装一些Markdown库,例如
MarkdownDeep
2) Add Helper function. 2)添加助手功能。 Notice, you should trim lines, as
<summery>
is parsed as-is with all trailing whitespaces after newlines. 请注意,您应该修剪行,因为
<summery>
会按原样解析,并且在换行符之后的所有尾随空格都将被解析。 Otherwise all markdown lists etc, wont be correctly parsed. 否则,所有降价清单等都将无法正确解析。
@functions {
string ToMarkdown(string str)
{
var lines = str.Split('\n');
var whitespaceCount = 0;
var i = 0; //from 2. Line
var imax = lines.Count();
while (++i < imax)
{
var line = lines[i];
if (whitespaceCount != 0)
{
lines[i] = line.Substring(whitespaceCount);
continue;
}
var trimmed = line.TrimStart();
if (trimmed.Length == 0 || trimmed == line) continue;
whitespaceCount = line.Length - trimmed.Length;
i--;
}
str = string.Join("\n", lines);
var md = new MarkdownDeep.Markdown {ExtraMode = true, SafeMode = false};
return md.Transform(str);
}
}
3) Preprocess the documentation string output 3)预处理文档字符串输出
<p>@Html.Raw(ToMarkdown(description.Documentation))</p>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.