-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix issue #115 #123
fix issue #115 #123
Conversation
@taoqf Ready to go. Let me know if you have any questions. |
@@ -260,7 +261,7 @@ export default class HTMLElement extends Node { | |||
// Whitespace node, postponed output | |||
currentBlock.prependWhitespace = true; | |||
} else { | |||
let text = node.text; | |||
let text = (<TextNode>node).trimmedText; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reinstates the trim functionality (prior to 3.3.2) with our special trim, which should produce a cleaner output.
So many thanks, I don't have much time on this rep recently, so I am going to merge your pr and publish another version now. |
No problem! I know how it is. Thanks for the quick merge! |
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