Skip to content

Instantly share code, notes, and snippets.

@ybonnel
Created April 8, 2016 06:46
Show Gist options
  • Save ybonnel/ea1e0249b5686614eed489131b7beea3 to your computer and use it in GitHub Desktop.
Save ybonnel/ea1e0249b5686614eed489131b7beea3 to your computer and use it in GitHub Desktop.
Array.from(document.querySelectorAll('.message'))
.map(message => message.querySelector('.body'))
.forEach(message => {
message.innerHTML = message.innerHTML.split(/ /).map(function (part, index) {
if (part && part.length && part.length > 0) {
var codeMatch = part.match(/(?:```(\w*)[\n ]?([\s\S]*?)```+?)|(?:`(?:[^`]+)`)/);
var imgHrefMatch = part.match(/href=/i);
if (!codeMatch && !imgHrefMatch) {
return part.replace(/(https?:\/\/.*\.(?:png|jpeg|jpg|gif))/i, '<img src="$1" />');
} else {
return part;
}
}
}).join(' ');
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment