From 089fcac67ae3c3e83e2c330498d211e6b7693534 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 26 Mar 2012 22:37:04 +0200 Subject: [PATCH] syntax highlighting with geshi --- README.rst | 8 ++++++++ data/templates/display.htm | 2 +- src/Phorkie/File.php | 13 +++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index ea8a940..1cc749b 100644 --- a/README.rst +++ b/README.rst @@ -35,3 +35,11 @@ Internal directory layout Search ====== Use ``ack-grep`` + + +Install geshi +============= +:: + + $ pear channel-discover mediawiki.googlecode.com/svn + $ pear install mediawiki/geshi diff --git a/data/templates/display.htm b/data/templates/display.htm index ea2e2cd..43a76fc 100644 --- a/data/templates/display.htm +++ b/data/templates/display.htm @@ -10,7 +10,7 @@

raw

-
{{file.getContent}}
+ {{file.getHighlightedContent|raw}} {% endfor %} {% endblock %} diff --git a/src/Phorkie/File.php b/src/Phorkie/File.php index 14a7bbf..6e71de3 100644 --- a/src/Phorkie/File.php +++ b/src/Phorkie/File.php @@ -57,6 +57,19 @@ class File return file_get_contents($this->path); } + public function getHighlightedContent() + { + /** + * Yes, geshi needs to be in your include path + * We use the mediawiki geshi extension package. + */ + require 'MediaWiki/geshi/geshi/geshi.php'; + $geshi = new \GeSHi($this->getContent(), $this->getType()); + $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); + $geshi->set_header_type(GESHI_HEADER_DIV); + return $geshi->parse_code(); + } + public function getMimeType() { $type = $this->getType(); -- 2.30.2