From 10f9c153a3b342fa9a113506b6d8e97486ff70d5 Mon Sep 17 00:00:00 2001 From: Titus Date: Wed, 20 Jun 2012 17:16:40 -0600 Subject: [PATCH] Added Google Prettify extension (output modification extension test) --- src/extensions/google-prettify.js | 30 ++++++++++++++++++++++ test/extensions/google-prettify/basic.html | 7 +++++ test/extensions/google-prettify/basic.md | 6 +++++ 3 files changed, 43 insertions(+) create mode 100644 src/extensions/google-prettify.js create mode 100644 test/extensions/google-prettify/basic.html create mode 100644 test/extensions/google-prettify/basic.md diff --git a/src/extensions/google-prettify.js b/src/extensions/google-prettify.js new file mode 100644 index 0000000..c262a4f --- /dev/null +++ b/src/extensions/google-prettify.js @@ -0,0 +1,30 @@ + +// +// Google Prettify +// A showdown extension to add Google Prettify (http://code.google.com/p/google-code-prettify/) +// hints to showdown's HTML output. +// + +(function(){ + + var prettify = function(converter) { + return [ + { type: 'output', filter: function(source){ + + return source.replace(/(
)?/gi, function(match, pre) {
+                    if (pre) {
+                        return '
';
+                    } else {
+                        return '';
+                    }
+                });
+            }}
+        ];
+    };
+
+    // Client-side export
+    if (typeof window !== 'undefined' && window.Showdown && window.Showdown.extensions) { window.Showdown.extensions.googlePrettify = prettify; }
+    // Server-side export
+    if (typeof module !== 'undefined') module.exports = prettify;
+
+}());
diff --git a/test/extensions/google-prettify/basic.html b/test/extensions/google-prettify/basic.html
new file mode 100644
index 0000000..13c7f40
--- /dev/null
+++ b/test/extensions/google-prettify/basic.html
@@ -0,0 +1,7 @@
+
+

Here's a simple hello world in javascript:

+ +
alert('Hello World!');
+
+ +

The alert function is a build-in global from window.

\ No newline at end of file diff --git a/test/extensions/google-prettify/basic.md b/test/extensions/google-prettify/basic.md new file mode 100644 index 0000000..fba19fa --- /dev/null +++ b/test/extensions/google-prettify/basic.md @@ -0,0 +1,6 @@ + +Here's a simple hello world in javascript: + + alert('Hello World!'); + +The `alert` function is a build-in global from `window`. \ No newline at end of file