From d6d7f807ea132df1636776e77881200a5b225420 Mon Sep 17 00:00:00 2001 From: Corey Innis Date: Wed, 31 Oct 2012 03:38:46 -0700 Subject: [PATCH] [#14] add initial github-flavored extension simply handles strike-through for now. --- compressed/extensions/github.js | 5 +++++ src/extensions/github.js | 25 +++++++++++++++++++++++++ src/extensions/google-prettify.js | 1 - src/extensions/twitter.js | 1 - src/showdown.js | 4 ++-- test/extensions/github/basic.html | 5 +++++ test/extensions/github/basic.md | 3 +++ 7 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 compressed/extensions/github.js create mode 100644 src/extensions/github.js create mode 100644 test/extensions/github/basic.html create mode 100644 test/extensions/github/basic.md diff --git a/compressed/extensions/github.js b/compressed/extensions/github.js new file mode 100644 index 0000000..bec428e --- /dev/null +++ b/compressed/extensions/github.js @@ -0,0 +1,5 @@ +// +// Github Extension (WIP) +// ~~strike-through~~ -> strike-through +// +(function(){var a=function(a){return[{type:"lang",regex:"(~T){2}([^~]+)(~T){2}",replace:function(a,b,c,d){return""+c+""}}]};typeof window!="undefined"&&window.Showdown&&window.Showdown.extensions&&(window.Showdown.extensions.github=a),typeof module!="undefined"&&(module.exports=a)})(); \ No newline at end of file diff --git a/src/extensions/github.js b/src/extensions/github.js new file mode 100644 index 0000000..c4f8682 --- /dev/null +++ b/src/extensions/github.js @@ -0,0 +1,25 @@ +// +// Github Extension (WIP) +// ~~strike-through~~ -> strike-through +// + +(function(){ + var github = function(converter) { + return [ + { + // strike-through + // NOTE: showdown already replaced "~" with "~T", so we need to adjust accordingly. + type : 'lang', + regex : '(~T){2}([^~]+)(~T){2}', + replace : function(match, prefix, content, suffix) { + return '' + content + ''; + } + } + ]; + }; + + // Client-side export + if (typeof window !== 'undefined' && window.Showdown && window.Showdown.extensions) { window.Showdown.extensions.github = github; } + // Server-side export + if (typeof module !== 'undefined') module.exports = github; +}()); diff --git a/src/extensions/google-prettify.js b/src/extensions/google-prettify.js index c262a4f..2c29e3c 100644 --- a/src/extensions/google-prettify.js +++ b/src/extensions/google-prettify.js @@ -1,4 +1,3 @@ - // // Google Prettify // A showdown extension to add Google Prettify (http://code.google.com/p/google-code-prettify/) diff --git a/src/extensions/twitter.js b/src/extensions/twitter.js index 2758452..cde3379 100644 --- a/src/extensions/twitter.js +++ b/src/extensions/twitter.js @@ -1,4 +1,3 @@ - // // Twitter Extension // @username -> @username diff --git a/src/showdown.js b/src/showdown.js index 081e0a9..6c24396 100644 --- a/src/showdown.js +++ b/src/showdown.js @@ -139,7 +139,7 @@ if (typeof module !== 'undefind' && typeof exports !== 'undefined' && typeof req // Options: // -// Parse extensinos options into separate arrays +// Parse extensions options into separate arrays if (converter_options && converter_options.extensions) { // Iterate over each plugin @@ -190,7 +190,7 @@ this.makeHtml = function(text) { // attacklab: Replace ~ with ~T // This lets us use tilde as an escape char to avoid md5 hashes // The choice of character is arbitray; anything that isn't - // magic in Markdown will work. + // magic in Markdown will work. text = text.replace(/~/g,"~T"); // attacklab: Replace $ with ~D diff --git a/test/extensions/github/basic.html b/test/extensions/github/basic.html new file mode 100644 index 0000000..af2b069 --- /dev/null +++ b/test/extensions/github/basic.html @@ -0,0 +1,5 @@ +

github-flavored markdown adds support for:

+ + \ No newline at end of file diff --git a/test/extensions/github/basic.md b/test/extensions/github/basic.md new file mode 100644 index 0000000..0ef04a3 --- /dev/null +++ b/test/extensions/github/basic.md @@ -0,0 +1,3 @@ +[github-flavored markdown](http://github.github.com/github-flavored-markdown/) adds support for: + + * ~~strike-through text~~