WPF 的轻量级文本库?
有谁知道一个轻度标记文本到样式文本格式化库(即类似 Markdown# 或 Textile.NET 的东西),但它会生成本机 XAML 文档(或者更确切地说,FlowDocument 模型或类似的模型,可以直接显示在 WPF 应用程序中),以避免使用 Web 浏览器?
轻量级的奖励积分。我希望能够容忍源文本中非常频繁的更新。
或者,是否有可以在 WPF 中使用的轻量级 HTML 渲染控件? (我不认为标准 WebBrowser 是轻量级的。)
Does anyone know of a lightly-marked-up-text to styled-text formatting library (ie. something like Markdown# or Textile.NET), but which produces a native XAML document (or rather, a FlowDocument model or similar that can be displayed directly in a WPF app), to avoid the use of a WebBrowser?
Bonus points for something lightweight. I'm hoping for something that will tolerate very frequent updates in the source text.
Alternatively, is there a lightweight HTML rendering control that can be used in WPF? (I don't consider the standard WebBrowser to be lightweight.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道有这样一个预先构建的库,但我确实有一些想法可能对您有所帮助。
我脑海中的第一个大问题是,当您可以使用 RichTextBox 时,为什么要使用像 Markdown 这样的原始东西。由于浏览器的限制,StackOverflow 和类似网站需要 Markdown。但如果您的应用程序是 WPF,这不是问题。
关于您可能想要这样做的原因的一种猜测是您希望您的文档在 WPF 和最低公分母 Web 应用程序中都是可编辑的。在这种情况下,您将需要一个将 Markdown 呈现为 HTML 的引擎,那么为什么不利用同一引擎将 Markdown 转换为 XAML呢?
将任意 HTML 转换为 XAML 非常困难,但转换 Markdown 转换器输出的 HTML 类型则完全是另一回事。大多数 Markdown 风格的转换器仅输出一些简单的 HTML 标签,所有这些标签都可以轻松转换为等效的 XAML。
如果您使用 Markdown 到 HTML 转换器,它将为您完成所有繁重的工作(解析文本等),并为您留下一个相对容易解析的类似 XML 的文档(准确地说是 HTML) 。此外,如果您在其他地方使用 Markdown 到 HTML 转换器,您将确信您的 Markdown 解析器将在 HTML 和 XAML 中以完全相同的方式解析您的 Markdown 语法,因为在每种情况下它都是相同的解析器。
所以基本上我的想法是:
围绕 Markdown 引擎实际输出的内容设计 MarkdownHtmlToXamlTranslator 的实现。它可以是一个非常简单的 XSLT,或者您可以使用 LINQ to XML 以及 XDocument 构造技术。无论哪种方式,它都应该是非常小的代码。
I don't know of such a library pre-built, but I do have some thoughts for you that may be helpful.
The first big question in my mind is why you want to use something primitive like Markdown when you could be using RichTextBox. Markdown is required for StackOverflow and similar sites because of the limitations of the browser. But if your app is WPF this is not an issue.
One guess as to why you might want to do this is that you want your documents to be editable both in WPF and in a lowest-common-denominator web application. In that case you will need an engine that renders the markdown to HTML anyway, so why not leverage that same engine to convert the markdown to XAML?
Converting arbitrary HTML to XAML is very difficult, but converting the sort of HTML that a Markdown converter would spit out is another matter entirely. Most Markdown-style converters spit out only a few simple HTML tags, all of which are trivially convertible to equivalent XAML.
If you use an Markdown-to-HTML converter it will have done all of the really heavy lifting for you (parsing the text, etc) and left you with an XML-like document (HTML to be precise) that is relatively easy to parse. Also, if you are using the Markdown-to-HTML converter elsewhere you will have confidence that your Markdown parser will parse your Markdown syntax exactly the same for both HTML and XAML use because it will be the same parser in each case.
So basically what I am thinking is:
Where you design your implementation of MarkdownHtmlToXamlTranslator around whatever the markdown engine actually spits out. It could be a very simple XSLT, or you could use LINQ to XML along with XDocument construction techniques. Either way it should be a very small bit of code.