-
-
Save nilbus/5941067 to your computer and use it in GitHub Desktop.
Showdown.extensions['twitter'] = function(converter) { | |
return [ | |
// Replace escaped @ symbols | |
{ type: 'lang', regex: '\\@', replace: 'red' } | |
]; | |
} |
that didnt work i got
[00:27:32.095] SyntaxError: missing ; before statement @ http://0.0.0.0:3000/assets/extensions/twitter.js?body=1:15
[00:27:32.104] uncaught exception: Extension 'undefined' could not be loaded. It was either not found or is not a valid extension.
(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;
}());
also you're not returning text.replace
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;
}());
Since this version didn't do what we expected
let's try the other format that they suggest in the README: