javascriptnode.jscheerio

How to get source code location information of node with Cheerio?


I'm trying to get the source code location of node.

There is parse5 (use by cheerio) sourceCodeLocationInfo option. But with this test code :

const cheerio = require('cheerio');

const $ = cheerio.load('<html><head><title>Test page</title></head><body></body></html>', { sourceCodeLocationInfo: true })
let title = $('title');

console.log(title.text());
console.log(title.sourceCodeLocation);

sourceCodeLocation property of title is undefined.

Any ideas?


Solution

  • This is because the Cheerio version on NPM is not up to date.

    Version 1.0.0-rc.3 is available and not version 1.0.0.

    From GitHub, I installed version 1.0.0 this way npm install https://github.com/cheeriojs/cheerio.git#v1.0.0. Everything is OK.