Skip to content

Instantly share code, notes, and snippets.

@nilbus
Created July 6, 2013 19:57
Show Gist options
  • Save nilbus/5941067 to your computer and use it in GitHub Desktop.
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' }
];
}
@nilbus
Copy link
Author

nilbus commented Jul 8, 2013

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