I came across what I thought would be a pretty simple challenge, whereas I needed to quickly stripe white space from an HTML document, so I could stuff it into a database to be referenced by another job. I assumed, somebody would have created a webp age that magically striped white space for me, and I’d be off and rolling with my proof of concept – nope. 10 minutes of Google turned up no such page, so after some experimenting this is what I came up with..
This is a simple and yet very powerful “trick”. Almost any code editor should do the trick, I used Visual Studio.
Here’s how it works:
- Open a document,
- Click inside Code View,
- Create an empty line,
- Left-click in the margin on the left hand-side of that empty line (it should turn black on Windows, blue on Mac),
- Select Menu > Edit > Find and Replace (keyboard shortcut: Ctrl + F),
- Select “Replace All” and you’re done.
Be aware that “trimming” can do serious damage and break things apart. In Dreamweaver, I understand even line breaks are removed and you end up with one tidy run-on string. In VS however, I had to manually remove line breaks, which wasn’t too bad, considering the find/replace did most the work for me.
Hope it helps you if you find yourself quickly needing to stripe whitespace.
Notepad++ does this directly.
open HTML file in Notepad++
click Language / HTML to see it formatted in HTML
click TextFX / TextFX Edit / Delete Blank Lines
click File / Save As …
You’re done!
Notepad++ is free from SourceForge.net