Html Serializer retains excess whitespace between tags
See original GitHub issueFor example,
Html.deserialize(`<div>
<strong>Test</strong>
</div>`)
Will render Test with four leading spaces. I’m not sure if you want to leave this up to the developer to implement their own rules, but I believe we should provide a foundation that follows spec.
I would recommend changing the default text node rule at html.js#L41 to something like:
if (el.type == 'text') {
let text = el.data
// Strip extra spaces
if (!text.trim()) text = el.next && el.prev ? ' ' : ''
return {
kind: 'text',
text: text,
}
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Tidy strips whitespace after HTML tags AND adds newlines ...
css that uses the display:inline property for list items), the stripped whitespace in tags OR the added newlines between tags becomes important) ...
Read more >Preserve whitespace between tags HTML - Stack Overflow
HTML won't invent whitespace when it's not in the source. You can always say: <a>one</a> <a>two</a>. if you want whitespace.
Read more >5 Ways to Insert Spaces in HTML - wikiHow
1. Open your HTML code in a text editor. You can use any text editor, such as Notepad for Windows, or TextEdit for...
Read more >YAML Ain't Markup Language (YAML™) revision 1.2.2
Local tags start with “ ! ”, are not URIs and are not expected to be globally unique. YAML provides a “ TAG...
Read more >Jinja Documentation (3.0.x) » Template Designer ...
A Jinja template doesn't need to have a specific extension: .html , .xml , or any other ... You must not add whitespace...
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
Whitespace normalization is not very straightforward; your change may break formatting in
<pre>
elements for example.In serializers/html.js#L94, you can try changing
to
cheerio will pass this option directly to the underlying htmlparser2, unfortunately it does not do a proper job.
I had much better results running incoming html through htmlclean before passing it to cheerio. But it seems to rely on regex and if this is the case I wouldn’t trust it unless you knew incoming HTML was always well-formed.
Got it. Thank you very much. On Mon, Jan 8, 2018 at 19:48 Ian Storm Taylor notifications@github.com wrote: