Maintain tag attribute quote characters
See original GitHub issueCheerio changes attributes with single quotes into double quotes.
var cheerio = require('cheerio');
// uses 'single quotes'
var $ = cheerio.load('<div attr=\'value\'></div>')
$.html();
// => <div attr="value"></div>
// has "double quotes"
This is useful for me, as I use JSON in HTML attributes for widget settings.
<div data-settings='{ "option": true }'></div>
Which is encoded with HTML entities (possibly breaking JSON) as
<div data-options="{ "option": true }"></div>
Setting decodeEntities: false
is encoded and breaks HTML
<div data-options="{ "option": true }"></div>
Ideally, cheerio would preserve which quote character is used. I understand this is an edge case, so I’m reporting it in case others run into it. Similar to #460
Issue Analytics
- State:
- Created 8 years ago
- Reactions:5
- Comments:14 (2 by maintainers)
Top Results From Across the Web
Unquoted attribute values in HTML and CSS/JS selectors
Attributes are placed inside the start tag, and consist of a name and a value, separated by an = character. The attribute value...
Read more >Do HTML attributes need quotation marks? - Stack Overflow
Attributes are placed inside the start tag, and consist of a name and a value, separated by an "=" character. The attribute value...
Read more >Special Characters in HTML - DeGraeve.com
Special Characters in HTML ; right double quote, ” ; double low-9 quote, „ ; dagger, † ; double dagger, ‡ ; per...
Read more >Quoting in HTML: Quotations, Citations, and Blockquotes
Blockquote tags are used for distinguishing quoted text from the rest of ... Both <q> and blockquotes can use a citation ( cite...
Read more >Escape Quotation Marks in Attribute Values - InformIT
I usually don't bother. Even inside attribute values, you only need to escape the kind of quote that delimits the attribute value. Because ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I fix this. steps:
To
I just had this problem and fixed it by adding
decodeEntities: false
to the props when loading the html: