Skip to content

Instantly share code, notes, and snippets.

@markshust
Created December 14, 2015 18:56
Show Gist options
  • Select an option

  • Save markshust/06c7b17383bc795d60eb to your computer and use it in GitHub Desktop.

Select an option

Save markshust/06c7b17383bc795d60eb to your computer and use it in GitHub Desktop.
underscore mixin to convert image urls to img tags
_.mixin({
imageToImg: function(html) {
const regEx = /(https?:\/\/.*\.(?:jpg|jpeg|gif|png))/g;
if (regEx.test(html)) {
const embed = '<img src="$1" />';
html = html.replace(regEx, embed);
}
return html;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment