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.)
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:
string html = MarkdownEngine.MarkdownToHtml(markdown);
string xaml = MarkdownHtmlToXamlTranslator.HtmlToXaml(html);
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.
Related
I have set of XSL-FO documents which are used for PDF generation. Also I have a requirement to get the same output data (which are in PDF) exported as an HTML file. Further, I need the HTML to have a similar styles as in PDF.
Is there any way to convert XSL-FO to XHTML using C#?
NOTE : I know one option is to use "RenderX:FO2HTML". But since it's a commercial product, I would like to learn about any other options available and do a comparison before continuing further.
I use the RenderX fo2html stylesheet a lot, and I recommend it to my customers because it is zero cost. Thus I have built it into a number of client solutions. You have to go through the RenderX online store to get it, but it costs nothing.
Write or find an XSLT stylesheet which converts XSL-FO into XHTML, modify it if necessary to get the rendering you require? Websearching "XSL-FO to HTML" finds at least one such.
Though this is somewhat backward. Normally the document starts in some semantic markup language (such as XHTML), and a stylesheet converts it into XSL-FO for rendering.
I am writing software which displays a lot of mathematical content. As in windows forms it is already hard to set a subscript or a Greek letter in a label, I am thinking of switching to WPF.
At the moment I am searching for the best way to render a mathematical expression, a formula or just a symbol inside my graphical user interface. They have to be shown in labels or drawn graphs/pictures. No live/just-in-time renderings but beautiful fix symbols.
What is the best way to do that? I thought, that MathML should be supported well, but I can't find a lot regarding that. I would be glad to hear some advice.
Here is, where I can get my symbols from (or what I would prefer):
LaTeX-code (First choice! Code is already there and same appearance in Software and documentation would be marvellous)
MathML-code (LaTeX-code in Word 2007 or higher -> Word equations -> copy as plain MathML to clipboard)
SVG (some rendering of LaTeX in Inkscape and export to XAML)
xmcd Files (Mathcad XML Document. Don't know how, but at least it's XML)
html Files (written by LaTeX->html or Mathcad->html
What I wouldn't consider personally, but maybe there are good solutions to:
Images (png-icons, pdf, dvi, eps, svg directly imported)
Symbols (like copy pasted from Character Map. Don't like the fonts, wouldn't find all I need and exchange of formula syntax would not be given)
I think using LaTeX, MathML or html would be great as they could be used for documentation as well. I also could think about exporting calculation results to *.tex files or internally generate graphics completely with LaTeX (tikz, pgfplots...)
Consider using open-source WPF-Math library (disclaimer: I'm its' current maintainer).
It can help you to display the LaTeX expression in a WPF window. It also uses vector graphic instead of bitmaps, so the formulae will scale nice on the modern displays.
I would go with pure xaml approach using datatemplates. There is no need for another vector format or rednering engine.
You can use datatemplate for each expression in expression tree. Using viewboxes you can achieve stretching, so topmost expressions will be larger then inner expressions. Your datatemplates will generate visual tree from you expression tree. I mean there will be contentpresenters inside contentpresenter.
The great advatage is that the expression visualisation can be responsive and interactive, just like math expression in MS Word, or Excel.
I could help you with implementation, since this is not trivial, if you are not familiar with wpf datatemplates
As far as I can see, the best rendering (on paper) is achieved with a late conversion from a vector file. I would prefer using either GDI+ (System.Drawing) or WPF (System.Media) to render a formula. Let me know if we can collaborate on a WPF solution.
I used https://github.com/std8590/xmcd2cs to convert most of my Mathcad xmcd files to C#.
Then I used the formulas in code and make the input variables available in UI.
Is there a markup language that can be used in conjunction with a well supported .net open source project to generate PDF or HTML documents with very fine control on the output in terms of style and anchoring for both ?
Documents will part be static and part auto generated from the xml comments of some class libraries.
To Clarify the question, I Know html is a markup language, The reason I don't want to use it to directly store the content is because all of the HTML to PDF tools and libraries I have looked at contain patchy support for creating tables of contents, indexes and turning hyperlinks in to PDF document anchors.
I would opt for HTML documents. Markdown comes to mind. But as far as 'very fine' control goes arbitrarily, you can always just use HTML.. it is THE HyperText Markup Language after all.
There were many questions like this before on stackoverflow. I think the consensus is that you should have one markup language, rather than two.
HTML is - by definition (hypertext MARKUP LANGUAGE) - the markup language of choice and all you need to do is convert that to PDF. The other way around, from PDF to HTML is quite a bit tougher.
In order to convert HTML to PDF there's a truckload of tools, depending on what exact needs you have for the resulting PDF and what kind of CSS you need to support.
I'd always go for a rendering engine that's used in browsers (instead of something like iText or Prince), because you want to make sure your docs look like they do in a browser. You'd end up with Winnovative or something based on WebKit like the API by htm2pdf.
XSL-FO is the recommended solution. It provides a great level of control over the document layout and there are several tools for XSL-FO to PDF comversion.
I'm working on a browser-like application which gets HTML from a site (any website) then applies a style-script over it to change certain elements (just like greasemonkey).
My initial plan is to parse the HTML using XPath and XmlDocument, but is there a better way?
Thanks in advance!
Ps> Handy tips, tricks & links on HTML+C# would be great~ ^^
use the HTML Aglility pack. You can find it here: http://www.codeplex.com/htmlagilitypack
HTML is not always follows XML rules, for example there are tags in html, that may not have close tag, so XPath and XDocument will sometimes throw errors. IE API gives you ability to do that(see here), you can also find 3-rd party parsers for that (see this o this)
I would highly recomend using XSLT. This allows you to keep all your transformational data OUTSIDE your code, and therefore, making it really easy to change it if the HTML to be transformed is modified, or you want to change your layout.
Non the less, if using HTML and not XHTML, beware of possible errors. Non the less, using a Tidy library can help you overcome this.
I would really recommend using a package for your programming language of choice that handles all the oddities of HTML parsing. I've used Hpricot in Ruby before and it's made things a breeze.
If you want to be able to browse the HTML based on its content, XPath is a good choice. But you'll have to clean up the HTML first. You can use HTML tidy to convert the HTML to XHTML. In the process you might modify how the page renders. But it seems to be the purpose of your project so that's not a big deal.
I have some formatted data that needs to be saved from the web page as a word document or rtf, something ubiquitous so I am thinking RTF. What is the easiest way to save something from .net as rtf? Are there built in tools for this or some plugins?
A tool like this does the trick for manual one-off conversions.
And if you want to do the same thing programmaticially
Personally, I think the formatting should be left out of the database. I'd much prefer seeing the data stored in a format-agnostic way. It might be useful for other purposes, and you can defer formatting choices until the last moment.