Created
April 8, 2016 06:46
-
-
Save ybonnel/ea1e0249b5686614eed489131b7beea3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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