-
Notifications
You must be signed in to change notification settings - Fork 29
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
Add a more aggressive whitespace removal option to the collapseWhitespace plugin #90
Add a more aggressive whitespace removal option to the collapseWhitespace plugin #90
Conversation
…hat removes incidental spacing such as tabs and newlines. Useful when there is a lot of structured markup and not much actual text. NOTE: a small behavioural change was introduced in order to match the documentation - single whitespace (newlines/tabs) are now replaced by a single space.
if (collapseType !== 'all') { | ||
collapseType = 'conservative'; | ||
} | ||
collapseType = (collapseType && validOptions.some(o=>o === collapseType)) ? collapseType : 'conservative'; |
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 could be simplified to
collapseType = (collapseType && validOptions.some(o=>o === collapseType)) ? collapseType : 'conservative'; | |
collapseType = validOptions.includes(collapseType) ? collapseType : 'conservative'; |
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.
Oh boy, I didn't know about the .includes method, I learnt something awesome today, thanks!
Although, I see you already merged the PR... so do you want a new PR for this simplification or do you want to just let it go?
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.
so do you want a new PR for this simplification or do you want to just let it go?
It's up to you :-)
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.
Always better to keep things tidy imho : #91
Thanks for your PR and sorry for the delay with getting back to you!
|
I would like to propose an addition/change to the 'collapseWhitespace' plugin to more aggressively remove semantically redundant whitespace.
I saw, looking at the output of my minified code, lots of spaces being introduced where none existed in my input. These turned out to be a translation of the indentation/newlines into a single space. Since almost all of the markup was structural none of those spaces were adding anything of value.
Therefore I suggest that a new 'aggressive' mode be introduced that removes structural/incidental whitespace such as this. Actual space characters can be collapsed but should not be removed as they are essential between inline tags (e.g. title</b> <i>part).
This pull request is a first attempt at implementing such behaviour.
Is this something you would consider for inclusion in the main htmlnano project?
NOTE: a small behavioural change was introduced to match the documentation - a single space now replaces individual newlines/tabs. I don't think this should have any impact on downstream consumers since html generally allows whitespace to be collapsed/replaced.