Skip to content
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

Trim plugin #825

Closed
wants to merge 2 commits into from
Closed

Trim plugin #825

wants to merge 2 commits into from

Conversation

telic
Copy link

@telic telic commented Nov 16, 2015

Trims blank lines from the beginning and end of code blocks, as well as removing indents and end-of-line whitespace.

This makes the "remove-initial-line-feed" plugin redundant.

This plugin needs to run before those that attach to the "complete" hook (e.g. line-numbers), or strange things may happen. There didn't appear to be any way to ensure this when running on "language-none" blocks, so I added a new "wont-highlight" hook for this use.

Useful for cases where "language-none" is specified, but a plugin still
needs to make some changes before "complete" to maintain consistency
with other code snippets.
@LeaVerou
Copy link
Member

I like the idea.
FWIW, to match \s without [\r\n] you could do something like /(?![\r\n])\s/
More info on this technique: http://lea.verou.me/2012/05/hacking-lookahead-to-mimic-intersection-subtraction-and-negation/

@telic
Copy link
Author

telic commented Nov 24, 2015

Yes, that would arguably make it more readable. The negative lookahead would need to be repeated for every character though (i.e. /(?:(?![\r\n])\s)+$/), which I imagine could be quite slow…

Here's a JSPerf test: http://jsperf.com/negated-vs-modified-class. Safari does especially poorly with the lookahead version for me.

@LeaVerou
Copy link
Member

Closing this, since the whitespace normalizer plugin already does this. Thanks for your efforts, I hope you contribute again in the future!

@LeaVerou LeaVerou closed this May 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants