donpark / html2jade

Converts HTML to Jade template. Not perfect but useful enough for non-daily conversions.
MIT License
1.18k stars 157 forks source link

Automatically assumes full HTML document #45

Closed thenoviceoof closed 10 years ago

thenoviceoof commented 11 years ago

In a templating/partial system, some html documents are included in other documents without being full pages. Auto wrapping each document in html/body seems unnecessary and not doing so facilitates the partial template case.

Example:

<span> hello </span>

=>

html
  body
    span
      | hello
donpark commented 11 years ago

Agreed but default behavior should not be changed for backward compatibility reasons. Instead, an CLI option should be added to indicate input is a document fragment. JSDOM should support doc fragments, I think.

taku0 commented 10 years ago

innerHTML might be used to get document fragment.

var jsdom = require("jsdom").jsdom;
var doc = jsdom("<html>", null, {});

doc.documentElement.innerHTML = "<span>Hello</span> <span>World</span>"

console.log(doc.documentElement.childNodes.item(0).nodeName);
console.log(doc.documentElement.childNodes.item(1).nodeName);
console.log(doc.documentElement.childNodes.item(2).nodeName);

doc.documentElement.innerHTML = "<html><head></head><documentElement></documentElement></html>"

console.log(doc.documentElement.childNodes.item(0).nodeName);
neverfox commented 10 years ago

No CLI option for this yet? Is it posing a challenge or is it just not high priority?

donpark commented 10 years ago

No. Just not high priority. Sorry. Pull requests are welcome.

donpark commented 10 years ago

--bodyless option in version 0.6.5+ disables default html and body wrappers.