*
* A set of replace-on-edit rules for automatically converting
* HTML to PmWiki markup
*
* Developed and tested using the PmWiki 2.2.0-beta series.
*
* To install, add the following line to your configuration file :
include_once("$FarmD/cookbook/convert-html.php");
*
* For more information, please see the online documentation at
* http://www.pmwiki.org/wiki/Cookbook/ConvertHTML
*
* 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['ConvertHTML']['Version'] = '2008-10-05';
SDVA( $ROEPatterns, array(
'#
\s*(.*?)\*s\n*#is' => "(: title $1:)\n",
'#\n*#i' => "(:$2 $4:)\n",
'##' => "%comment% $1 %%",
'#<(ul|ol|dl)\s+([^>]+)>\s*(<(li|dt)\b[^>]*>)#i' => '<$1>$3%apply=list $2% ',
'#<(li|dt)\s+([^>]+)>#i' => "<$1>%apply=item $2% ",
'#\s*\s*\s*\s*(.*?)\n?#is' => "\n:$1:$2\n",
'#\s*(<(ul|ol)\s*>\s*)\n?#ise' => 'ConvertHtmlList(PSS("$1"))',
'#\n?#is' => "\n(:table$1:)$2\n(:tableend:)",
'#\n?]*)?>(.*?) | #is' => "\n(:cell$1:)$2",
'#\n?]*)?>\s*\(:cell\b(.*?)
#is' => "\n(:cellnr$1$2",
'#<(p|h\d)\s+([^>]+)>#i' => "<$1>%block $2% ",
'#\n*(.*?)\n*#ise' => "\"\n\n\".str_repeat('!','$1').\" $2\n\"",
'#\n*\s*(.*?)
\n?#is' => "\n\n$1\n",
'#\n*]*)?>\s*(.*?)\n?
\n*#is' => "\n(:div$1:)$2\n(:divend:)\n",
'#]*)>(.*?)#ise' => '"%".ConvertHtmlSpan(PSS("$1"))."% $2 %%"',
'#\n*\s*(.*?)
\n*#is' => "\n->$1\n",
'#
\n*#i' => "\\\\\\\n",
'#\n*
\n*#i' => "\n----\n",
'#?(i|em)>#i' => "''",
'#?(b|strong)>#i' => "'''",
'#?(code|tt)>#i' => "@@",
'#(.*?)
#is' => "[@$1@]",
'#(.*?)#is' => "'+$1+'",
'#(.*?)#is' => "'-$1-'",
'#(.*?)#is' => "'^$1^'",
'#(.*?)#is' => "'_$1_'",
'#(.*?)#is' => "{+$1+}",
'#(.*?)#is' => "{-$1-}",
'#(<(?:a|img)\b[^>]+\b(href|src)=)([\'"])([./][^\'"]*?)\3#i' => "$1$3Path:$4$3",
'#]*\bname=([\'"])([^\'"]*?)\1[^>]*>(.*?)#is' => "[[#$2]] $3",
'#]*\bhref=([\'"])([^\'"]*?)\1[^>]*>(.*?)#is' => "[[$2|$3]]",
'##i' => "$2",
'#]*)\bsrc=([\'"])([^\'"]*?)\2\s([^>]*?)\s*/?>#i' => '%apply=img $1$4%$3%%',
));
function ConvertHtmlSpan($param) {
return preg_replace(
array( '/%/', '/(?:class|style)=([\'"])(.*?)\1/' ),
array( 'pct', '$2' ),
$param );
}
function ConvertHtmlList($html) {
$out = '';
$lit = array();
$html = preg_replace('#(?(?:ol|ul|li))\b([^>]+)>#i','$1>',$html);
$lia = preg_split( '#\s*(?(?:ol|ul|li)\s*>)\s*#i', $html, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
foreach( $lia as $n ) switch($n) {
case '':
$lit[] = "\n".str_repeat( '*', count($lit)+1 ).' ';
break;
case '':
$lit[] = "\n".str_repeat( '#', count($lit)+1 ).' ';
break;
case '
':
case '':
array_pop($lit);
break;
case '':
if($lit) $out .= end($lit);
break;
case '':
break;
default:
$out .= $n;
}
return $out;
}