WPF简洁的文本库? [英] Lightly styled text library for WPF?

查看:156
本文介绍了WPF简洁的文本库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道一个轻微标记文本到样式文本格式化库(即像Markdown#或Textile.NET之类的东西),但它生成一个原生XAML文档(或者更确切地说,一个FlowDocument模型或类似可以直接在WPF应用程序中显示),以避免使用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.

或者,是否有一个轻量级的HTML呈现控件,可以在WPF中使用? (我不认为标准的WebBrowser是轻量级的。)

Alternatively, is there a lightweight HTML rendering control that can be used in WPF? (I don't consider the standard WebBrowser to be lightweight.)

推荐答案

我不知道这样的库,

在我心中的第一个大问题是,为什么要使用像Markdown这样的原语,当你可以使用RichTextBox。由于浏览器的限制,StackOverflow和类似网站需要Markdown。但是如果你的应用程序是WPF,这不是一个问题。

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.

一个猜测为什么你可能想这样做是因为你希望你的文档可编辑的WPF和最低公共分母Web应用程序。在这种情况下,你需要一个引擎,将markdown转换为HTML,所以为什么不使用同一引擎将markdown转换为XAML?

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?

将任意HTML转换为XAML是非常困难的,但转换一种Markdown转换器将吐出的HTML是另一回事。大多数Markdown风格的转换器只有几个简单的HTML标签,所有这些都可以简单地转换为等效的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.

如果你使用Markdown转HTML将完成所有的真正繁重的工作(解析文本等),并留给你一个类似于XML的文档(要精确的HTML),这是相对容易解析。此外,如果您在其他地方使用Markdown-HTML转换器,您将有信心您的Markdown解析器将解析您的Markdown语法与HTML和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.

所以基本上我想是:

string html = MarkdownEngine.MarkdownToHtml(markdown);
string xaml = MarkdownHtmlToXamlTranslator.HtmlToXaml(html);

在这里你设计MarkdownHtmlToXamlTranslator实现围绕任何markdown引擎实际吐出。它可以是一个非常简单的XSLT,或者你可以使用LINQ到XML以及XDocument构造技术。无论哪种方式,它都应该是一小段代码。

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.

这篇关于WPF简洁的文本库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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