[BUG] Consecutive spans render whitespace differently in grapes' editor than in ordinary window
Question
I've spent the greater part of an afternoon trying to debug this. While I have reduced this to a small and easy to reproduce test case, I didn't find the root cause of this issue yet. Hopefully someone can help.
Note the following HTML template:
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 0;
}
.navbar-main .main-navigation__list {
margin: 0;
padding: 0;
}
.navbar-main .main-navigation__list .main-navigation__list-item {
display: inline-block;
}
</style>
</head>
<body>
<nav class="navbar-main">
<div>
<ol class="main-navigation__list">
<li class="main-navigation__list-item">
<span>Our solution</span>
</li>
<li class="main-navigation__list-item">
<span>About</span>
</li>
</ol>
</div>
</nav>
</body>
</html>
If you render this in a browser, it renders as:
<img width="133" alt="screen shot 2018-03-29 at 1 36 34 pm" src="https://user-images.githubusercontent.com/331833/38112278-47c661fe-3356-11e8-8186-d48791b01af7.png">Notice the whitespace between "Our solution" and "About".
If you then use the exact HTML and style as Grapes's template, it will render as:
<img width="173" alt="screen shot 2018-03-29 at 1 36 44 pm" src="https://user-images.githubusercontent.com/331833/38112304-5c2592dc-3356-11e8-83b6-946b68cc2c59.png">Notice that the whitespace is now not visible. The expected behavior is for grapes to render the template in the same manner as a browser does without grapes.
JSFiddle to reproduce:
https://jsfiddle.net/szLp8h4n/89/
Change autorender: 0 to autorender: 1 to trigger the bug.
Could this be because Grapes has a manual HTML and CSS parser, meaning that the DOM or CSS rules are replicated invalidly in this particular case? Can you figure out where it goes wrong?
Answers (3)
Yeah Tom thanks, I think a configurable option (eg. keepWhitespace?!?) might be a good solution
This is due to the node cleaning while traversing https://github.com/artf/grapesjs/blob/dev/src/parser/model/ParserHtml.js#L155-L158
Thanks @artf, I see. I would suggest removing this or at least making this configurable (defaulting to true then to prevent breaking changes). Would you accept a PR for this?
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1699
[BUG] Link elements are not copyable/deletable
In the editor, if we have link element with some classes, the editor does not allow to copy/delete the element. GrapesJS version: v0.14.50S...
Issue #1980
[BUG]: RTE Editor not scrolling
The Toolbar of the RTE Editor is not visible vor Text field higher than the Browserwindow. While scrolling to the middle the RTE Toolbar is...
Issue #1865
[Bug]: Grapes change page position
Hello, I found the following problem using grapes inside an html page: when you click on some elements of the editor, such as the arrow to...
Issue #708
Greapes editor cannot read "template" tag
When I try to save following html to grapes editor, its not able to render "template" tag. Regards
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.