Seed: HTML to seed convertor

Created on 4 Jul 2019  路  12Comments  路  Source: seed-rs/seed

It would be nice to have a tool which can convert html to seeds code.
So before digging and implementing one I first want to check that there are no such thing yet.

My plan is to make a library, which then can be used in cli tool as well as in wasm so it can be used in a simple web based converter.

Most helpful comment

And here is a web version (very raw) https://tatrix.org/public/html-to-seed/

All 12 comments

I was thinking something similar and had a loot at https://github.com/bodil/typed-html as a possible framework to do this with. The typed-html crate specifically supports emitting a walkable output. Only problem was that it required strings to be quoted, so that doesn't really solve your problem.
Also had a look at seed's ability to do "raw" elements (from string), which I ultimately concluded would work ok for things like layouts, etc.

I think the best approach would be to create a string (or output a text file) of element macros from a vdom tree, since we can create that tree use `El::from_html. Should be straightfwd.

Starting pseudocode:

fn html_to_vdom(html: String) -> String {
    let tree = El::from_html(html);
    let mut result = String::new();
    for el in tree {
        result += tag.as_str() + "[";
        if !el.attrs.is_empty() {
            result += "\n attrs!{";
            for attr, val in el.attrs.iter() {
                result += attr + "=" + val + ",";
            }
           result += "}"
        // etc
        }
    }
}

Probably I wasn't clear enough.
What I want is essentially a web page with a textarea to which I can copy html code and get a generated code to paste into my source files.
So paste <div>hi!</div> and get div!["hi"] back.

Yep, looks, good!

Here's some progress. I used html5ever and rustfmt for parsing and formatting respectively.
This means you can configure output format with rustfmt.toml.
2019-07-04-153701_2769x1019_scrot

And here is a web version (very raw) https://tatrix.org/public/html-to-seed/

@TatriX Please create PR to https://github.com/MartinKavik/awesome-seed-rs once it's at least beta version. I suggest to close the issue.

Sure, sounds good!

This would be a great addition to examples/ or something equivalent, or even a part of the seed website.

Agree on posting to awesome-seed-rs, and the website. I'm not sure how it would fit as an example, since it's a tool. This would be a great learning tool/reference, in addition to using it to convert things.

Perhaps just the website then, it's just very handy when you have snippets to convert to the macro format. But its just an idea.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MartinKavik picture MartinKavik  路  6Comments

TatriX picture TatriX  路  4Comments

flosse picture flosse  路  3Comments

mankinskin picture mankinskin  路  5Comments

bheisler picture bheisler  路  4Comments