HTML rendering using C #

Say I'm crazy and I want to implement a basic HTML rendering engine using C #. I would like to use WPF controls to display an HTML layout.

While there is no such opportunity, I still want to try! So which libraries, projects, and documentation will help me do this?

+4
source share
4 answers

Because WPF XAML is a superset of HTML features, almost all you need to do is map one to the other.

If your input is XHTML, you can simply use XSLT or LINQ-to-XML to get the data.

If you use XSLT, you will get XAML, which you parse with XamlReader.Parse () to get a UIElement that you can add to your window or other WPF container. This is probably more than using LINQ-to-XML, because XSLT is relatively limited.

If you use LINQ-to-XML, you can select XAML and then parse it, as with XSLT, or simply create an object tree directly. If you are creating XAML using LINQ-to-XML, I would write the translation code in VB.NET instead of C #, which is my usual preferred language. The VB.NET syntax "XML Literal" simplifies this part of the work.

If your input is arbitrary HTML, not XHTML, I would use a third-party library to convert it to XHTML and work from there. Handling all HTML parsing is a lot of work and probably mostly not related to your actual purpose.

If you just want to render HTML without turning it into WPF objects, you can use the Frame control.

+3
source

Html rendering will be a simple conversion to xaml file, and rendering should be pretty fast. You will get an accelerated browser with fast enlargement and fonts.

But how do you deal with css - will you need to create styles (Yuck)? DHTML, HTML5 and Java script. So many pages now require these thinsg which you cannot even browse.

An easy way for a Java script is to use each parser, there might be a better way (and a Java script for CIL compilers?)

+1
source

html parsers with typed mapping to xaml alternatives, interesting ... maybe you can use antlr for the lexer parser http://www.antlr.org/ , more specifically heres interesting codeproject, project http://www.codeproject.com/ KB / cs / TagBasedHtmlParser.aspx , you could try converting your html to xaml, which would be quite interesting :)

0
source

I think this project is exactly what you are striving to achieve:
https://htmlrenderer.codeplex.com/
Perhaps you can work on it and add support for HTML 5 and CSS 3!

0
source

Source: https://habr.com/ru/post/1301135/


All Articles