Cheerio: Missing whitespace in tag text between child elements

Created on 9 May 2019  路  2Comments  路  Source: cheeriojs/cheerio


If an element contains children then their text is concatenated without any white space in between, whereas it is expected that they would be separated by a space. For example:

const cheerio = require('cheerio');
const ch = cheerio.load('<body><div id="1">Some text in the div.</div><div id="2">There should be a space before this line.</div></body>');
ch('body').text();

Results in:
'Some text in the div.There should be a space before this line.'

But in many cases, the text should be separated resulting in:
'Some text in the div. There should be a space before this line.'

text() should provide an option to compulsorily separate children with a space.

All 2 comments

This behavior is equivalent to jQuery.

So what was the solution ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bxqgit picture bxqgit  路  3Comments

becush picture becush  路  3Comments

robogeek picture robogeek  路  4Comments

misner picture misner  路  3Comments

tndev picture tndev  路  4Comments