Skip to content

Instantly share code, notes, and snippets.

@ded
Created March 19, 2011 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ded/877800 to your computer and use it in GitHub Desktop.
Save ded/877800 to your computer and use it in GitHub Desktop.
there's probably a better way to do this
/* replace faux text (sometimes html) into html with paragraphs - or whatever that thing wordpress does to their posts */
function paragraphs(story) {
story = story.replace(/<pre>([\s\S]*)<\/pre>/g, function (m, content) {
return '<pre>' + content.replace(/\n/g, 'iiiiii') + '</pre>';
});
return _(story.split('\n')).compact().map(function(par, i) {
return par == '' || par.match(/^(<p(?:re)?>|\s+)/) ? par : '<p>' + par + '</p>';
}).join('\n').replace(/<p><\/p>/g, '').replace(/(i{6})/g, '\n');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment