Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the dart:html library to write html files?

Tags:

html

dart

I want to make a program that prepares an HTML file. It would either be on the server side or just running in my local machine.

I think it would be nice to be able to use the dart:html library since it has a lot of methods for manipulating html (obviously). But it is thought to be used dynamically on the client side, and I want to use it like this: manipulate an html DOM tree with dart:html, and when its ready, write a static html file. For instance using query('body').innerHtml

The problem I'm running into is that I if start a project with the "console application" template, I am not able to make dart:html talk to an html file. And if I choose "web application", in which I am able to do this, I cannot load the dart:io library, maybe it has to do with it being tagged as [server] in the SDK?

Of course I could just do:

print(query('body').innerHtml);

and manually copying the output to a file, but I thought maybe there is a more elegant solution.

like image 734
Fernando Tiberti Avatar asked Nov 07 '25 02:11

Fernando Tiberti


1 Answers

See html5lib.

html5lib in Pure Dart

This is a pure Dart html5 parser. It's a port of html5lib from Python. Since it's 100% Dart you can use it safely from a script or server side app.

Eventually the parse tree API will be compatible with dart:html, so the same code will work on the client or the server.

It doesn't support much in the way of queries yet.

like image 129
Greg Lowe Avatar answered Nov 09 '25 19:11

Greg Lowe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!