瀏覽代碼

Added Google Prettify extension (output modification extension test)

Titus 13 年之前
父節點
當前提交
10f9c153a3

+ 30 - 0
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(/(<pre>)?<code>/gi, function(match, pre) {
+                    if (pre) {
+                        return '<pre class="prettyprint linenums" tabIndex="0"><code data-inner="1">';
+                    } else {
+                        return '<code class="prettyprint">';
+                    }
+                });
+            }}
+        ];
+    };
+
+    // 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;
+
+}());

+ 7 - 0
test/extensions/google-prettify/basic.html

@@ -0,0 +1,7 @@
+
+<p>Here's a simple hello world in javascript:</p>
+
+<pre class="prettyprint linenums" tabIndex="0"><code data-inner="1">alert('Hello World!');
+</code></pre>
+
+<p>The <code class="prettyprint">alert</code> function is a build-in global from <code class="prettyprint">window</code>.</p>

+ 6 - 0
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`.