Hi everyone!
I am looking for a way to parse wikicode in a plugin.
First some pretext to see if I understood the proccedings how dokuwiki deals with a page right.
As I understand, parsing is done before dokuwiki deals with plugins, so basically
$renderer->doc .= "First Line \\ Second Line";
in a plugin will not work because parsing of wikisyntax is already finished when the above code is executed. Am I right on that?
On the other hand there are plugins like the note plugin, which allow you to use wikisyntax with them, for example
<note>First Line \\ Second Line</note>
will work, because the text within the note tags is parsed with the rest of the text, before the plugins are dealt with, right?
Now, I have got a page that looks like this:
needle1|Some text \\ Some more text
needle2|Whatever it is \\ Even more
...
What I am now looking for is a plugin which searches this page for a given searchterm and outputs the text after the pipe with the correct formatting, for example \\ are linebreaks not printed like "\\".
The plugin pretty much works, except the formatting issue.
Could anybody give me some hints how to get this working?
The plugin so far looks like this:
<?php
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
class syntax_plugin_entrypoints extends DokuWiki_Syntax_Plugin {
function getInfo(){
return array(
'author' => 'Scarecrow',
'email' => 'crw1985@gmx.de',
'date' => '2007-10-10',
'name' => 'Extended Entrypoint Plugin',
'desc' => 'Includes entrypoints from a list',
'url' => 'http://wiki.splitbrain.org/wiki:plugins',
);
}
function getType(){ return 'container'; }
function getPType(){ return 'normal'; }
function getAllowedTypes() {
return array('container','substition','protected','disabled','formatting','paragraphs');
}
function getSort(){ return 195; }
// override default accepts() method to allow nesting
// - ie, to get the plugin accepts its own entry syntax
function accepts($mode) {
if ($mode == substr(get_class($this), 7)) return true;
return parent::accepts($mode);
}
function connectTo($mode) {
$this->Lexer->addEntryPattern('<s_key.*?>(?=.*?</s_key>)',$mode,'plugin_entrypoints');
}
function postConnect() {
$this->Lexer->addExitPattern('</s_key>','plugin_entrypoints');
}
function handle($match, $state, $pos, &$handler){
switch ($state) {
case DOKU_LEXER_ENTER :
break;
case DOKU_LEXER_UNMATCHED :
$search_entrypoint = $match;
$inputlist = file(DOKU_PLUGINS . "../../data/pages/entrypoints/entrypoint.txt");
$entrylist = array_fill(0,1,"entrylist");
$entrypoints = array_fill(0,1,"entrypoints");
$beschreibung = array_fill(0,1,"beschreibung");
foreach($inputlist as $value){
$value = explode("|",$value);
array_push($entrypoints,$value[0]);
array_push($beschreibung,$value[1]);
}
$temp = array_shift($entrypoints);
$temp = array_shift($beschreibung);
$search_entrypoint = explode(",",$search_entrypoint);
$hit = array_search($search_entrypoint[0],$entrypoints);
return array($state, $beschreibung[$hit]);
default:
return array($state);
}
}
function render($mode, &$renderer, $indata) {
if($mode == 'xhtml'){
list($state, $data) = $indata;
switch ($state) {
case DOKU_LEXER_ENTER :
$renderer->doc .= '<p>';
break;
case DOKU_LEXER_UNMATCHED :
$renderer->doc .= $renderer->_xmlEntities($data);
break;
case DOKU_LEXER_EXIT :
$renderer->doc .= "\n</p>";
break;
}
return true;
}
// unsupported $mode
return false;
}
}
//Setup VIM: ex: et ts=4 enc=utf-8 :
?>
So when using
<s_key>needle1</s_key>
it should print something like:
Some text
Some more text
Thanks in advance
Scarecrow