Skip to content

Return html fragments without html, head and body tags - #157

Open
auscaster wants to merge 1 commit into
jonkemp:masterfrom
auscaster:keep-html-fragments
Open

auscaster wants to merge 1 commit into
jonkemp:masterfrom
auscaster:keep-html-fragments

Conversation

@auscaster

Copy link
Copy Markdown

Fixes #117.

Since the move to cheerio 1.x, a fragment comes back as a full document:

await inlineCss('<div class="a">Hi</div><style>.a { color: red; }</style>', { url: 'file:///' })
// before: '<html><head></head><body><div class="a" style="color: red;">Hi</div></body></html>'
// after:  '<div class="a" style="color: red;">Hi</div>'

cheerio 1.x parses input as a document unless load is told otherwise by its third argument. lib/inline-css.js, style-data and list-stylesheets now pass false for that argument unless the input has a doctype or an html, head or body tag, so full documents parse exactly as before. All three needed it, because each stage parses and serialises the html again.

Each of the three suites has a new test for a fragment, and all three fail without the change. Every existing fixture is a full document, and all 66 tests pass. The changeset bumps all three packages as a patch.

cheerio 1.x parses input as a full document by default, so a fragment came
back wrapped in <html><head></head><body>. inline-css, style-data and
list-stylesheets now load input as a fragment unless it has a doctype or an
html, head or body tag.

Fixes jonkemp#117
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cheerio 1.x wraps code with html tags

1 participant