Remove Multiple New Lines with JavaScript
I'm blessed in that lots of people want to guest post on this blog. It's really flattering and I love seeing writers get a bunch of attention after writing. My task is converting the blog post, in whatever format it's provided in (HTML, Markdown, PDF, Google Doc, etc.), to HTML for my blog, which can sometimes get messy. I employ a host of regular expressions to fix these formatting issues. And the number one problem? Loads of extra new lines (\n
).
The Regular Expression
The regular expression is actually quite simple:
content.replace(/[\r\n]+/g, '\n'); // Just one new line
content.replace(/[\r\n]+/g, '\n\n'); // "document" formatting, more elegant
With the dozens of extra lines gone it's much easier to work with the content!
Your early CSS books were instrumental in pushing my love for front end technologies. What was it about CSS that you fell in love with and drove you to write about it?
At first blush, it was the simplicity of it as compared to the table-and-spacer...
If you follow me on Twitter, you know that I've been working on a super top secret mobile application using Appcelerator Titanium. The experience has been great: using JavaScript to create easy to write, easy to test, native mobile apps has been fun. My...
Although it's possible to achieve opacity using CSS, the hacks involved aren't pretty. If you're using the MooTools JavaScript library, opacity is as easy as using an element's "set" method. The following MooTools snippet takes every image with the "opacity" class and sets...
Row highlighting and individual cell highlighting in tables is pretty simple in every browser that supports :hover on all elements (basically everything except IE6). Column highlighting is a bit more difficult. Luckily MooTools 1.2.3 makes the process easy.
The XHTML
A normal table. The cells...
David,
I’m more inclined to use something like:
Only there always seems to be some extra whitespace between those newlines. If you don’t want to loose the tabs on the next line then this works just as well