This repository has been archived by the owner on Sep 27, 2024. It is now read-only.
Fix unwanted extra paragraphs after HTML parsing #820
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The editor may be initialised with arbitrary HTML content however, it currently misbehaves when supplied HTML that contains new lines and indentation.
For example, consider the following HTML snippet:
This snippet contains valid HTML but the editor would not understand that the new lines and and spacing are for formatting and indenting the markup, rather than to be displayed as text characters.
The resulting AST contains lots of stray paragraphs and new line characters in the text, which is not correct:
Solution
Instead of treating new lines as text, treat new lines (and adjacent spacing) within HTML as indentation:
After this change, the AST now looks like:
See this JSFiddle example where the same behaviour is shown.