When you do
$b.text($a.text());
you lose the new lines coming from <BR> elements.
This is consistent with what you have in jQuery but jQuery users have the option to use innerText which doesn't have the same problem (contrary to textContent).
Would a PR adding a new textln function be welcome or should cheerio users just monkey patch when they need to preserve new lines ?
The goal of this project is parity with jQuery's DOM manipulation/traversal API, so I don't think a custom function is in-scope.
You can write you own method. Like this:
$.prototype.textln = function () {
this.find('br').replaceWith('\n');
this.find('*').each(function () {
$(this).replaceWith($(this).html());
});
return this.html();
}
$('a').textln();
Thanks, @alanev!
Most helpful comment
You can write you own method. Like this: