Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize outputs the doctype at the end / DOM Level2 Unavailable #29

Open
stevesims opened this issue May 18, 2011 · 7 comments
Open

Comments

@stevesims
Copy link

If I try to serialize out a document, html5 is outputting the doctype at the end, rather than the beginning.

My simple-ish test-case code is:

var jsdom = require('jsdom');
var HTML5 = require('html5');
var window = jsdom.jsdom(null, null, {parser: HTML5, features: { QuerySelector: true }}).createWindow();
var parser = new HTML5.Parser({document: window.document});
parser.parse("<!DOCTYPE html><html><head></head><body></body></html>");
console.log(HTML5.serialize(window.document))

What I see outputted to console is:

<html><head></head><body></body></html><!DOCTYPE html>
@aredridel
Copy link
Owner

Alright. I'll see what I can do.

@aredridel
Copy link
Owner

Ah, you're getting a DOM Level 1 from JSDOM -- Level 2 is required to get doctypes right, I think.

@aredridel
Copy link
Owner

What I end up getting is TypeError: Object #<Object> has no method 'createDocumentType' running your code.

I'm working with @tmpvar and @isaacs to get npm and/or jsdom to export the level 2 stuff more easily to fix this properly.

@stevesims
Copy link
Author

I must admit that I struggled quite a bit to get html5 up and running - I've been doing browser-based JS for years, but am fairly new to node.js. It took me a while to figure out that I needed to set up a NODE_PATH environment variable to point to places where npm was installing things, otherwise html5 was just refusing to see jsdom at all. (Getting document.querySelector was important for me - I only managed to work that out by searching through jsdom's test code...) Chances are I've not got things set up quite "right", which probably explains why we're seeing differing results.

For now I've worked around this problem by using a regex to move the doctype from the end of the outputted HTML to the beginning.

I'll keep an eye out for updates - would be nice to remove my bodge. :-)

@aredridel
Copy link
Owner

Sweet. I'll keep working on the integration issues. It's mostly about getting jsdom's API to be more friendly to use via npm. I'll see about that!

@tmpvar
Copy link

tmpvar commented May 20, 2011

yeah, to be honest jsdom is pretty hosed on my local machine. I'll spend some time getting back to "a good place" this weekend

@aredridel
Copy link
Owner

Awesome! Poke me by twitter if you want help testing anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants