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!
CSS animations are a lot of fun; the beauty of them is that through many simple properties, you can create anything from an elegant fade in to a WTF-Pixar-would-be-proud effect. One CSS effect somewhere in between is the CSS flip effect, whereby there's...
I was inspired when I first saw Addy Osmani's original ShineTime blog post. The hover sheen effect is simple but awesome. When I started my blog redesign, I really wanted to use a sheen effect with my logo. Using two HTML elements and...
A few days back I debuted a sweet article that made use of MooTools JavaScript and opacity to show focus on a specified element. Here's how to accomplish that feat using jQuery.
The jQuery JavaScript
There you have it. Opacity is a very simple but effective...
The ability to place content into a user's clipboard can be extremely convenient for the user. Instead of clicking and dragging down what could be a lengthy document, the user can copy the contents of a specific area by a single click of a mouse.
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