danceric (owner)

Revisions

gist: 113004 Download_button fork
public
Description:
patch for PHP Markdown Extra 1.2.3 to use GeSHi to add syntax coloring to code block. first line of your codeblock need to be the language in square bracket. ie: [PHP]
Public Clone URL: git://gist.github.com/113004.git
Embed All Files: show embed
PHP_Markdown_Extra+GeSHi.patch #
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
49
50
51
52
53
54
55
56
57
58
59
--- markdown-extra.php 2008-12-31 07:26:58.000000000 -0500
+++ markdown-extra-geshi.php 2009-05-17 08:51:16.000000000 -0400
@@ -15,6 +15,7 @@
 define( 'MARKDOWN_VERSION', "1.0.1m" ); # Sat 21 Jun 2008
 define( 'MARKDOWNEXTRA_VERSION', "1.2.3" ); # Wed 31 Dec 2008
 
+require_once realpath(dirname(__FILE__) . '/../geshi-1.0.8.3/geshi.php');
 
 #
 # Global default settings:
@@ -68,7 +69,7 @@
 ### WordPress Plugin Interface ###
 
 /*
-Plugin Name: Markdown Extra
+Plugin Name: Markdown Extra +GeSHi
 Plugin URI: http://www.michelf.com/projects/php-markdown/
 Description: <a href="http://daringfireball.net/projects/markdown/syntax">Markdown syntax</a> allows you to write using an easy-to-read, easy-to-write plain text format. Based on the original Perl version by <a href="http://daringfireball.net/">John Gruber</a>. <a href="http://www.michelf.com/projects/php-markdown/">More...</a>
 Version: 1.2.2
@@ -1107,12 +1108,20 @@
  $codeblock = $matches[1];
 
  $codeblock = $this->outdent($codeblock);
- $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES);
 
  # trim leading newlines and trailing newlines
  $codeblock = preg_replace('/\A\n+|\n+\z/', '', $codeblock);
 
- $codeblock = "<pre><code>$codeblock\n</code></pre>";
+ // if it start w/ a language tag, use GeSHi to convert the code
+ if (preg_match('/^\[(\w+)\]\s*/', $codeblock, $match)) {
+ $codeblock = str_replace("[${match[1]}]\n", '', $codeblock);
+ $geshi = new GeSHi($codeblock, $match[1]);
+ $codeblock = $geshi->parse_code();
+ } else {
+ $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES);
+ $codeblock = "<pre><code>$codeblock\n</code></pre>";
+ }
+
  return "\n\n".$this->hashBlock($codeblock)."\n\n";
  }
 
@@ -2819,6 +2828,14 @@
 
 }
 
+// If there's command line argument, markdownify the file from the first argument
+if (!empty($argv[1])) {
+ $filename = realpath($argv[1]);
+ if (file_exists($filename)) {
+ $rawtext = file_get_contents($filename);
+ echo Markdown($rawtext);
+ }
+}
 
 /*