diff --git a/lib/helpers.js b/lib/helpers.js index fed4908..e71bbe7 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -68,22 +68,10 @@ function objectToAttributes(obj) { }, ""); } -/** - * Checks for `` tag in a string. - * - * @param {string} content The content - * @return {boolean} `True` if body tag, `False` otherwise. - */ -function hasBodyTag(content) { - const hasBody = /<\s*body(\w|\s|=|"|-)*>/gm; - return hasBody.test(content); -} - module.exports = { isUrl, isAllowedExtension, parseStringToNumbers, generateWidths, objectToAttributes, - hasBodyTag, }; diff --git a/lib/img2picture.js b/lib/img2picture.js index 474c511..845295e 100644 --- a/lib/img2picture.js +++ b/lib/img2picture.js @@ -10,7 +10,6 @@ const { generateWidths, parseStringToNumbers, objectToAttributes, - hasBodyTag, } = require("./helpers.js"); /** @@ -210,7 +209,7 @@ async function generateImage(attrs, options) { */ async function replaceImages(content, options) { const { extensions, fetchRemote } = options; - const $ = cheerio.load(content); + const $ = cheerio.load(content, null, false); let images = $("img") .not("picture img") // Ignore images wrapped in .not("[data-img2picture-ignore]") // Ignore excluded images @@ -243,7 +242,7 @@ async function replaceImages(content, options) { $(images[i]).replaceWith(picture); }); - return hasBodyTag(content) ? $.html() : $("body").html(); + return $.html(); } /** diff --git a/package.json b/package.json index e122776..1154d05 100644 --- a/package.json +++ b/package.json @@ -23,18 +23,18 @@ "license": "MIT", "dependencies": { "@11ty/eleventy-img": "^2.0.1", - "cheerio": "^1.0.0-rc.10", + "cheerio": "^1.0.0-rc.11", "debug": "^4.3.4" }, "devDependencies": { "ava": "^3.15.0", - "eslint": "^8.15.0", + "eslint": "^8.16.0", "eslint-config-prettier": "^8.5.0", - "eslint-config-xo-space": "^0.32.0", + "eslint-config-xo-space": "^0.33.0", "eslint-plugin-prettier": "^4.0.0", "husky": "^8.0.1", "image-size": "^1.0.1", - "lint-staged": "^12.4.1", + "lint-staged": "^13.0.0", "nyc": "^15.1.0", "prettier": "^2.6.2", "rimraf": "^3.0.2"