question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

$.html() encoding apostrophes

See original GitHub issue

Having quotes in quotes and calling html on it encodes the inside quotes. jQuery .html correctly returns the desired output (not replace ' with ')

console.log(require('cheerio').load('<div ng-include="\'views/main.html\'"></div>').html());
// <div ng-include="&apos;views/main.html&apos;"></div>

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:25 (9 by maintainers)

github_iconTop GitHub Comments

7reactions
alexindigocommented, Jul 26, 2014

Have you tried to run it with decodeEntities: false?

console.log(require('cheerio').load('<div ng-include="\'views/main.html\'"></div>', {decodeEntities: false}).html());
5reactions
terryweisscommented, Dec 18, 2013

I’ll jump in on this one. In my case I am appending an image tag with a src url with query params. In theory, it should not matter that it replaces the & with &. But it does matter because in this case: the output is an email, not a browser and the & is being interpreted as written so that my query params come in as amp;qname. I have a workaround which to unescape the output of .html(), but really I should not have to in this case and I have some concerns about what may happen if a legitimately escaped string comes in and we unescape it. Anyway, food for thought.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML code for an apostrophe - ascii - Stack Overflow
Use &apos; for a straight apostrophe. This tends to be more readable than the numeric &# ...
Read more >
How to create the apostrophe symbol in HTML - Educative.io
An entity name, entity number, or hexadecimal can be used to add special characters/symbols to an HTML webpage. One such symbol is the...
Read more >
Should I escape the Apostrophe ( ' ) character with its HTML ...
"If your apostrophe belongs to content, escape it." - This would seem to be incorrect (as if missing the word "don't"). If the...
Read more >
HTML Entities - W3Schools
Some Useful HTML Character Entities ; &, ampersand, & ; " double quotation mark, " ; ' single quotation mark (apostrophe), &apos; ;...
Read more >
How do I show an apostrophe in HTML? - Gzipwtf.com
Encoding. The letter apostrophe is encoded at U+02BC ʼ MODIFIER LETTER APOSTROPHE (HTML ʼ ). In Unicode code charts it looks identical to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found