1<?php 2if(!defined('DOKU_INC')) die(); 3if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 4require_once(DOKU_PLUGIN.'action.php'); 5/** 6 * @license GNU GPLv2 version 2 or later (http://www.gnu.org/licenses/gpl.html) 7 * 8 * @class plugin_ckgedit_edit 9 * @author Myron Turner <turnermm02@shaw.ca> 10 usage: place ~~R_STUDIO~~ at the top of the RStudio page before saving the copy/paste, then save 11 */ 12class action_plugin_rstudio extends DokuWiki_Action_Plugin { 13 function register(Doku_Event_Handler $controller) { 14 $controller->register_hook( 'IO_WIKIPAGE_WRITE', 'BEFORE', $this, 'insert_geshi'); 15 } 16 17 function insert_geshi(&$event,$params) { 18 if(strpos($event->data[0][1],'~~R_STUDIO~~') === false) return; 19 $event->data[0][1] = preg_replace_callback( 20 '|(<code>(?!</file>).*?)</file>|sm', // '|(<code>.*?)</file>|sm', 21 function ($matches) { 22 return $matches[1] . '</code>'; 23 }, 24 $event->data[0][1] 25 ); 26 $event->data[0][1] = str_replace('<code>', '<code rsplus>', $event->data[0][1]); 27 28 $event->data[0][1] = preg_replace_callback( 29 '|(={2,})\s*(\[\[.*?\]\])\s*(\1)|sm', 30 function ($matches) { 31 return "**" .$matches[2] . "**\n\n"; 32 }, 33 $event->data[0][1] 34 ); 35 36 $event->data[0][1] = preg_replace('#^\n(\s{2,}\*)\s*#sm', "$1", $event->data[0][1]); 37 38 } 39} 40