====== regExReplacer Plugin ====== ---- plugin ---- description: Replaces text by regular expressions. author : Robert Jäckel / MLU Halle-Wittenberg email : robert.jaeckel@verwaltung.uni-halle.de type : plugin-creator,syntax lastupdate : 2012-01-26 compatible : Rincewind depends : conflicts : similar : plugin:replace tags : replace macro regex plugins ---- The Code was adapted from [[plugin:replace]]. This Plugin creates a syntax-plugin for each row in your config-file. ===== Installation ===== - Search and install the plugin using the [[plugin:extension|Extension Manager]]. Refer to [[:Plugins]] on how to install plugins manually. - create the config file in the default conf-path ===== Configuring the Plugin ===== The Plugin uses the config-file to create [[devel:syntax_plugins]] dynamically. The File consists of three columns: - parserPattern - preg_replace search-string \\ :!: followed by a tab - preg_replace replacement-string ==== example config ==== # inhaltsverzeichnisse \@toc\:[^\r\n!]*[!|\r?\n] \@toc\:([^\r\n!]*)!? {{topic>${1}}} # tagcloud \@cloud[^\r\n]*[\r\n?|\n] \@cloud([^\r\n]*) ~~TAGCLOUD${1}~~ # no-cache-feature \@nocache[\r\n?|\n] \@nocache ~~NOCACHE~~ # set tags \@tags\:[^\r\n]*[\r\n?|\n] \@tags\:([^\r\n]*) {{tag>${1}}} # include template \@tpl\:[^\r\n]*[\r\n?|\n] \@tpl\:([^\r\n]*) {{template>${1}}}@info: Eingebettet aus //[[${1}]]//* # newpage-helper \@newpage[\r\n?|\n] \@newpage {{NEWPAGE>}} \@newpage\:[^\r\n]*[\r\n?|\n] \@newpage\:([^\r\n]*) {{NEWPAGE>${1}}} # workflow easing \@fixme\:[^\r\n]*[\r\n?|\n] \@fixme\:([^\r\n]*) FIXME ${1}{{tag>todo fixme}} # simple info-frame \@info\:[^\r\n]*[\r\n?|\n] \@info\:([^\r\n]*) ${1} ===== plugin-script ===== 'Robert Jäckel', 'email' => 'robert.jaeckel@verwaltung.uni-halle.de', 'date' => '2012-01-12', 'name' => $this->realClassName, 'desc' => 'Anpassungen des Wikis an der MLU Halle-Wittenberg', 'url' => 'http://verwaltung.uni-halle.de', ); } function getType() { return 'substition'; } function getAllowedTypes() { return array('container','substition','protected','disabled','formatting','paragraphs'); } function render($mode, &$renderer, $data) { return true; } function getSort() { return 999; } function generateReplaceClass($setup/*=array($pattern,$search,$replace)*/) { $dir = self::$classDir.'modMLU_'.($idx=static::$subs++); @mkdir($dir); $file = $dir.'\\syntax.php'; $fHandle = fopen($file,'w+'); $generateStr = "$v) $generateStr.='protected $'.$k.' = \''.str_replace('\'','\\\'',$v)."';\r\n"; $generateStr .= 'protected $subIDX='.$idx.";\r\n}\r\n\r\n"; fwrite($fHandle,$generateStr); fclose($fHandle); return $idx; // generate subclass } function Syntax_Plugin_modMLU() { //read cfg-file and create subclasses if(isset(self::$modMLUconf)) return true; self::$classDir = dirname(__FILE__).'\\..\\'; $cfg = self::$modMLUconf = confToHash(DOKU_CONF . 'replaceMLU.conf'); $requires = ''; foreach($cfg as $pMatch=>$sAction) { $aAction = explode("\t",$sAction,2); $idx=$this->generateReplaceClass(array('pattern'=>$pMatch,'search'=>$aAction[0],'replace'=>$aAction[1],'realClassName'=>$this->realClassName.'_'.self::$subs)); } } function connectTo($mode) { if(!$this->pattern) return; $this->Lexer->addSpecialPattern($this->pattern,$mode, 'plugin_modMLU_'.$this->subIDX); //check for search string else return } function handle($match, $state, $pos, &$handler) { if ($this->nesting) { $handler->_addCall('cdata', array($match), $pos); } else { $this->nesting = true; $nestedWriter = & new Doku_Handler_Nest($handler->CallWriter); $handler->CallWriter = & $nestedWriter; /* add magic here */ $this->Lexer->parse(preg_replace('/'.$this->search.'/',$this->replace,$match)." \\\\ "); $nestedWriter->process(); $handler->CallWriter = & $nestedWriter->CallWriter; $handler->calls[count($handler->calls) - 1][2] = $pos; $this->nesting = false; } return false; } } ===== Problem ===== * How can I use this plugin? The download link is somewhat yield, so cannot install it. * However I've //mkdir regexreplacer// in the plugin directory and //mv modMLU.php syntax.php// and insert it into the new directory. Finally the plugin manager can recognize it but it doesn't work with its config file yet. (i.e. //replaceMLU.conf// file in the dokuwiki //conf// directory). Actually the //conf// directory of my server is not in the default location because I'd moved it for security. What is the problem? Why it doesn't work?