jfisteus / html2xhtml

Command-line HTML to XHTML converter
http://www.it.uc3m.es/jaf/html2xhtml/
Other
43 stars 23 forks source link

Generating a snippet #1

Closed avium closed 12 years ago

avium commented 12 years ago

I had a situation where I needed to translate snippets of HTML to valid XHTML, so I made a couple of minor modifications to your code so that one can optionally print the contents of the tag, minus the XML declaration, prolog, HTML tags, HEAD node, and BODY tags.

I imagine the general public may find this functionality useful for AJAX services, which very often dump an HTML snippet back into the DOM after an AJAX request returns a response.

Ideally - in addition to generating snippets - html2xhtml would be able to correctly parse them, too. Based on my (admittedly limited) testing, it couldn't do this.

jfisteus commented 12 years ago

Thanks. I find your idea useful. I've just merged your code.

However, I changed the way this feature is implemented in procesador.c (look at function write_document from commit 65356531d). I prefer this way because the feature is controled from just one function.

Regarding your comment about parsing snippets, some of them already work. For example:

./html2xhtml --generate-snippet ../tests/test-nested-p-1.html | ./html2xhtml --generate-snippet

Snippets whose root is not a block element fail to parse in strict DTDs (1.0 strict, 1.1, etc.) However, they seem to work with the XHTML 1.0 Transitional DTD, which is the default.

Please, open an issue if you have snippets that the program cannot parse. Paste some of the examples in the issue and I'll take a look.

avium commented 12 years ago

Thanks for the merge!

I'll follow up with you on the parsing side of things after I have a better idea about what's going on.

thanks.