Created
July 6, 2013 00:28
-
-
Save fuzeman/5938015 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
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