summaryrefslogtreecommitdiff
path: root/inc/parser/handler.php
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2009-07-26 19:51:58 +0200
committerAndreas Gohr <andi@splitbrain.org>2009-07-26 19:51:58 +0200
commit3d491f758802dd2376dddd5d001765b940b08743 (patch)
treea9b27250e2e19c33ad52c63e1e642924be03b5bc /inc/parser/handler.php
parenta6783fdb13cb5cc9b0225cb1ea1ac8c028a775da (diff)
downloadrpg-3d491f758802dd2376dddd5d001765b940b08743.tar.gz
rpg-3d491f758802dd2376dddd5d001765b940b08743.tar.bz2
enhanced <code> and <file> syntax
Ignore-this: 80398f84222bec1fce56eee8f107d37a This patch enhances the code and file syntax with several new features. 1. code and file are now essentially the same and just differ in the class name. This means you now can use the file syntax with syntax highlighting as well. This also solves problems where the code to highlight already contains a <code> tag (FS#1493) 2. a filename can be given as label for the code or file block. It is specified as second parameter after the language: <code html myfile.html>...</code> If no highlighting is wanted, but a filename shall be given, you can use a dash as language: <code - somefile.foo>...</code> 3. when a filename was given (as shown above), the label links to a download of the code given in the code/file block. This is made possible by a new renderer in inc/parser/code.php. The basename of given filename is suggested as filename when downloading. darcs-hash:20090726175158-7ad00-969641a06ae1393a6d99207c3cd938fb67f23a71.gz
Diffstat (limited to 'inc/parser/handler.php')
-rw-r--r--inc/parser/handler.php46
1 files changed, 22 insertions, 24 deletions
diff --git a/inc/parser/handler.php b/inc/parser/handler.php
index 83f837b70..58b68bc42 100644
--- a/inc/parser/handler.php
+++ b/inc/parser/handler.php
@@ -323,13 +323,6 @@ class Doku_Handler {
return true;
}
- function file($match, $state, $pos) {
- if ( $state == DOKU_LEXER_UNMATCHED ) {
- $this->_addCall('file',array($match), $pos);
- }
- return true;
- }
-
function quote($match, $state, $pos) {
switch ( $state ) {
@@ -360,23 +353,28 @@ class Doku_Handler {
return true;
}
- function code($match, $state, $pos) {
- switch ( $state ) {
- case DOKU_LEXER_UNMATCHED:
- $matches = explode('>',$match,2);
- $matches[0] = trim($matches[0]);
- if ( trim($matches[0]) == '' ) {
- $matches[0] = NULL;
- }
- # $matches[0] contains name of programming language
- # if available, We shortcut html here.
- if($matches[0] == 'html') $matches[0] = 'html4strict';
- $this->_addCall(
- 'code',
- array($matches[1],$matches[0]),
- $pos
- );
- break;
+ function file($match, $state, $pos) {
+ return $this->code($match, $state, $pos, 'file');
+ }
+
+ function code($match, $state, $pos, $type='code') {
+ if ( $state == DOKU_LEXER_UNMATCHED ) {
+ $matches = explode('>',$match,2);
+ $matches[0] = trim($matches[0]);
+
+ list($language,$filename) = explode(' ',$matches[0],2);
+ $language = trim($language);
+ $filename = trim($filename);
+ if ( $language == '' ) $language = null;
+ if ( $language == '-' ) $language = null;
+ if ( $filename == '' ) $filename = null;
+ # We shortcut html here.
+ if($language == 'html') $language = 'html4strict';
+ $this->_addCall(
+ $type,
+ array($matches[1],$language,$filename),
+ $pos
+ );
}
return true;
}