markdown - 如何在 Razor View 中呈现数据库中的 Markdown 文本?

标签 markdown servicestack

所以我正在处理我自己的自定义路由映射(而不是让 ServiceStack 自动处理它),仅仅因为我的所有数据都存储在数据库、页面内容和所有内容中。我有一系列 _Layout.cshtml 文件,我的 Markdown 存储为字符串。

所以我想我在问,我需要为映射的路由继承什么类型的服务(常规服务?),我需要返回到状态“在字符串 Y 中使用布局 X 和 Markdown ”?

我已经通读了 ServiceStack Wiki 和新示例页面上的示例,但无法找到任何示例来实现这一点(一切似乎都是从文件中读取 Markdown,而 Razor 从数据库中读取变量)。

如果我的问题不清楚,请告诉我,我很乐意相应地修改它。

——

编辑

一些澄清:

是的,我加载了常规的 Razor 页面。
是的,我从要加载的文件中获取了常规 Markdown。

我现在只是好奇如何将 Markdown 渲染到字符串中的 Razor 方法“RenderBody()”(来自我的数据库)。

最佳答案

如果你只是想渲染一个 Markdown 文本为 HTML (不是 Markdown Razor,即没有 Razor 功能!)您需要执行以下两个步骤:

var renderer = new MarkdownSharp.Markdown();
string html = renderer.Transform("___your_markdown_markup_here___");

例如,现在您只需要将呈现的 HTML 添加到您的 Razor View 中的适当位置。

但是,如果您的目标是渲染普通 Razor View 中的 Markdown View (即 ServiceStack 项目中的 .md 文件) ,你需要遵循这个报价:

Include Partial Markdown views in Razor pages

We loved Markdown and Razor so much that included in ServiceStack is an enhanced version of Markdown with Razor functionality and Syntax called Markdown Razor which should be instantly familiar to existing Razor users.

As we expect Razor + Markdown to be an increasingly popular combination we've extend @Html.Partial() support to also embed Partials from different View Engines. This feature lets you embed any Markdown Page as we've done in each of the content-heavy Rockstar pages using the standard Razor Partial syntax:

@Html.Partial("Content")

Which tells ServiceStack to embed a Partial named Content inside the page at that location. First it will look for a Partial named Content.cshtml followed by a Partial named Content.md if it reaches the Markdown Razor View Engine. Initially it searches the current directory, followed by any matching Partials in the /Views/Shared folder.



引自 http://razor.servicestack.net .

关于markdown - 如何在 Razor View 中呈现数据库中的 Markdown 文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12919153/

相关文章:

R - Markdown 避免包加载消息

javascript - Markdown -> detab 正则表达式中的摊牌错误?

c# - ServiceStack V4 API 文档缺少响应类型(在列表中)

servicestack - Typelite:DTO 中的日期映射到 Date,但实际上是 ISO8601 字符串

servicestack - 使用 API key 验证服务器到服务器的通信

markdown - 如何链接到 github markdown 中名称为 `/` 的部分

javascript - 我们应该使用哪种 Stack-Overflow 风格的 Markdown (WMD) JavaScript 编辑器?

rest - 使用 Markdown 创建 Jira 票证

c# - ServiceStack SOAP XmlException : The input document has exceeded a limit set by MaxCharactersInDocument

c# - Json.NET 转换器的 ServiceStack.Text 等价物是什么,例如应用于 NodaTime 类型时?