mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
Added Google Prettify extension (output modification extension test)
This commit is contained in:
parent
9d0a929fac
commit
10f9c153a3
30
src/extensions/google-prettify.js
Normal file
30
src/extensions/google-prettify.js
Normal 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;
|
||||||
|
|
||||||
|
}());
|
7
test/extensions/google-prettify/basic.html
Normal file
7
test/extensions/google-prettify/basic.html
Normal 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>
|
6
test/extensions/google-prettify/basic.md
Normal file
6
test/extensions/google-prettify/basic.md
Normal 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`.
|
Loading…
Reference in New Issue
Block a user