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.
Abstract
The following PR takes a holistic approach to mitigating issue #115 by implementing HTML-specific trim functionality, where necessary. Its aim is to provide a more accurate correction for the
trim()
issue by replicating trim, while explicitly preserving only single leading or trailing non-breaking whitespace, where present.Background
In addition to the already corrected area (
structuredText
) a second affected area was found.The purpose of
HTMLElement#removeWhitespace
is to remove unnecessary whitespace nodes and otherwise cleanup the text. To do this, it callstrim()
onTextNode
rawText. Unfortuntately, this is too greedy.Trim rightly removes repeating spaces, tabs, and line-breaks, which are often simply junk from multi-line HTML formatting. Unfortunately, it also removes legitimate, single, non-breaking space at the beginning or end of the text in a
TextNode
.Put more simply, it's overcorrecting in some scenarios. Here are some examples:
Solution
I've replaced the two calls to
trim()
with a cached accessor on eachTextNode
. The accessor performs the same action as trim, with the exception that it will allow a single non-breaking space before and after the text, if one is present.Associated Issues
#115
crosstype/node-html-markdown#9