-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwp-markdown-syntax-sugar.php
48 lines (40 loc) · 1.95 KB
/
wp-markdown-syntax-sugar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/*
Plugin Name: wp-markdown-syntax-sugar
Plugin URI: https://github.com/visoft/wp-markdown-syntax-sugar
Description: This WordPress plugin works to enhance the handling of code blocks in markdown syntax.
Version: 0.1.1
Author: Damien White (Visoft, Inc.)
Author URI: http://www.visoftinc.com
License: GPLv2 or later
*/
/*
Copyright 2012-2013 Visoft, Inc. <[email protected]>
This file is part of wp-markdown-syntax-sugar
WP Markdown Syntax Sugar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Collapsing Archives is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Collapsing Archives; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// Install filter to run after markdown (priority 6)
add_filter('the_content', 'wmss_process_markdown', 7);
add_filter('the_content_rss', 'wmss_process_markdown', 7);
add_filter('get_the_excerpt', 'wmss_process_markdown', 7);
function wmss_process_markdown( $text ) {
return preg_replace( '|<pre><code>#!([^\n]+)\n(.*?)</code></pre>|se', 'wmss_process_language(\'$2\',\'$1\');', $text);
}
function wmss_process_language( $code, $language) {
if(strcasecmp($language, 'xml') == 0) {
$code = stripslashes( trim( str_replace(array('&', ''', '"'), array('&','\'','"'), $code) ) );
} else {
$code = stripslashes( trim( htmlspecialchars_decode( $code, ENT_NOQUOTES ) ) );
}
return '<pre><code class="language-'. $language . '">' . $code . '</code></pre>';
}