Created
July 6, 2013 19:57
-
-
Save nilbus/5941067 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Showdown.extensions['twitter'] = function(converter) { | |
return [ | |
// Replace escaped @ symbols | |
{ type: 'lang', regex: '\\@', replace: 'red' } | |
]; | |
} |
it also may not support defining the extension outside of an AMD module
Hi Gus,
Fix the indentation, and you'll be able to better spot where the syntax error is.
(function(){
var twitter = function(converter) {
return [
{
type: 'lang',
filter: function(text) {
text.replace(/blue/g, 'red');
}
}
];
// Client-side export
if (typeof window !== 'undefined' && window.Showdown && window.Showdown.extensions) { window.Showdown.extensions.twitter = twitter; }
// Server-side export
if (typeof module !== 'undefined') module.exports = twitter;
}());
Now it's pretty easy to see that the closing }
is missing on the var twitter
function.
The comment about returning text.replace is correct. I've made that correction below.
The last comment is referring to how the server-side export won't work in the browser. The last lines are for detecting that (we copied them from the twitter example), though they could be replaced with one line since we know it'll be running in a browser.
Here's an example with all the changes:
(function(){
var twitter = function(converter) {
return [
{
type: 'lang',
filter: function(text) {
return text.replace(/blue/g, 'red');
}
}
];
}
window.Showdown.extensions.twitter = twitter;
}());
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
also you're not returning text.replace