*
* Real-time editing
*
* Developed and tested using PmWiki 2.2.0,
*
* To install, add the following to your config file:
include_once("$FarmD/cookbook/js-preview.php");
* For more information, please see the online documentation at
* http://www.pmwiki.org/wiki/Cookbook/...
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License,
* Version 2, as published by the Free Software Foundation.
* http://www.gnu.org/copyleft/gpl.html
*/
$RecipeInfo['js-preview']['Version'] = '2009-03-';
SDV( $HandleActions['js-markuprules'], 'HandleJavascriptMarkupRules' );
SDV( $HandleAuth['js-markuprules'], 'edit' );
if ( $action == 'edit' ) $HTMLHeaderFmt['js-preview'] = "
\n";
function HandleJavascriptMarkupRules( $pagename, $auth = 'edit' ) {
global $Charset, $BlockMarkups, $HTMLVSpace, $HTMLPNewline, $SuffixPattern, $LinkPattern, $UrlExcludeChars;
header("Content-type: text/javascript; charset=$Charset;");
$page = RetrieveAuthPage( $pagename, $auth, FALSE, READPAGE_CURRENT );
if (!$page) exit();
$mr = array(
'/&/g' => '"&"', '/ '"<"', '/>/g' => '">"',
'/^[ \t]*$/gm' => '"<:vspace>"' );
foreach ( BuildMarkupRules() as $pat => $rep ) if (preg_match( '#^(.)(.*)\1([a-df-z]*)$#is', $pat, $match )) {
$exp = str_replace( array( "\n", '(?>', '(?' ) {
$mr["/^\\(:(cell|cellnr|(?:div|table)\\d*(?:end)?)(\\s.*?)?:\\)/gim"] = 'MarkupCells';
$mr["/^(!{1,6})[ \t]?(.*)$/gm"] = "function( str, p1, p2 ) { return '<:block,1>'+p2+''; }";
$mr["/^(?=[ \t]*\\S)(?:<:([^>]+)>)?/gm"] = 'MarkupBlock';
$mr[str_replace( '[[:alnum:]]', '\w', "/\\[\\[\\s*(.+?)\\s*\\]\\]($SuffixPattern)/g" )] = 'MarkupLink';
$mr["/\\b((?:$LinkPattern)[^\\s$UrlExcludeChars]*[^\\s.,?!$UrlExcludeChars])()/g"] = 'MarkupLink';
} else if ( $exp == '\(:nl:\)' ) {
$mr['/\\\\(\\\\+)\n/g'] = 'function( str, p1 ) { return new Array(p1.length+1).join("
"); }';
}
}
//echo "/*".print_r($GLOBALS['MarkupRules'],1)."*/\n\n";
echo "var HTMLVSpace = \"$HTMLVSpace\";\nvar HTMLPNewline = \"$HTMLPNewline\";\nvar markup_pat = [";
echo implode( ",\n", array_keys($mr) );
echo "];\n\nvar markup_rep = [";
echo implode( ",\n", array_values($mr) );
echo '];';
}