Added Google Prettify extension (output modification extension test)

This commit is contained in:
Titus 2012-06-20 17:16:40 -06:00
parent 9d0a929fac
commit 10f9c153a3
3 changed files with 43 additions and 0 deletions

View File

@ -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;
}());

View File

@ -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>

View File

@ -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`.