Skip to content

Instantly share code, notes, and snippets.

@fuzeman
Created July 6, 2013 00:28
Show Gist options
  • Save fuzeman/5938015 to your computer and use it in GitHub Desktop.
Save fuzeman/5938015 to your computer and use it in GitHub Desktop.
define([
'jabbr/events'
], function (events) {
return function (processor) {
processor.bind(events.processor.beforeProcessPlainContent, function (event, handler) {
var re = /(?:\*|_)([^\*_]*)(?:\*|_)/g,
match = null,
result = handler.get();
//Replaces *test* occurrences in message with <i>test</i> so you can use italics
while ((match = re.exec(result)) != null) {
if (match[1].length > 0) {
var head = result.substring(0, match.index);
var tail = result.substring(match.index + match[0].length, result.length);
result = head + "<i>" + match[1] + "</i>" + tail;
}
}
handler.set(result);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment