* * A set of replace-on-edit rules for automatically converting * HTML to PmWiki markup * * Developed and tested using the PmWiki 2.2 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'] = '2011-02-16'; SDVA($ROEPatterns, array( '#^\n#' => '', // PLB - get rid of leading newline placed by markup2html '#\n\n$#' => '', // PLB - get rid of trailing newlines placed by markup2html '##' => '', // PLB - get rid of and from tables '#\[([=@]).*?\1\]#es' => "Keep(stripslashes('\$0'), 'H')", '#[ \t]*(\n?)\n*#i' => '$1', '#\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*(<(ul|ol)\s*>\s*)\n?#ise' => 'ConvertHtmlList(stripslashes("$1"))', '#\s*(.*?)(?:)?\s*\s*(.*?)(?:)?\n#is' => "\n:$1:$2\n", '#\s*#i' => '', '#\s*]*)?>(.*?)\s*#is' => "\n(:table$1:)$2\n(:tableend:)", "#\s*]*)?>(.*?)\\n?#is" => "\n(:cell$1:)$2", '#\s*]*)?>\s*\(:cell\b(.*?)(?:\n\s*)?#is' => "\n(:cellnr$1$2", '#

(.*?)\n

#is' => "\n$1", // PLB '#<(p|h\d)\s+([^>]+)>#i' => "<$1>%block $2% ", '#^(.*?)\n*#isme' => "str_repeat('!','$1').' '.stripslashes('$2').\"\n\"", '#\s*\s*(.*?)

\n?#is' => "\n\n$1\n", '#\s*\s*#is' => "\n\n", '#\s*
(\n{1,2})
\n#is' => "\n$1", // PLB '#\s*]*)?>\s*(.*?)\n?\n*#is' => "\n(:div$1:)\n$2\n(:divend:)\n", '#]*)>(.*?)#ise' => '"%".ConvertHtmlSpan(stripslashes("$1"))."% $2 %%"', '#\s*
\s*(.*?)
\n*#is' => "\n->$1\n", '#\n*#i' => "[[<<]]\n", '#
\n*#i' => "\\\\\\\n", '#\s*
\n*#i' => "\n----\n", '##i' => "''", '##i' => "'''", '##i' => "@@", '#
(.*?)
#is' => "[@$1@]", '#(.*?)#is' => "'+$1+'", '#(.*?)#is' => "'-$1-'", '#(.*?)#is' => "'^$1^'", '#(.*?)#is' => "'_$1_'", '#<(ins|u)>(.*?)#is' => "{+$2+}", '#(.*?)#is' => "{-$1-}", '#(<(?:a|img)\b[^>]+\b(href|src)=)([\'"])([./][^\'"]*?)\3#i' => "$1$3Path:$4$3", '#(<(?:a|img)\b[^>]+\b(href|src)=)([\'"])([^/:\'"]+\.[^/:\'"]+?)\3#i' => "$1$3Attach:$4$3", '#]*\bname=([\'"])([^\'"]*?)\1[^>]*>(.*?)#ise' => '"[[#".preg_replace("/\s+/","_",stripslashes("$2")).\']] $3\'', '#]*)>(.*?)#ise' => 'ConvertHtmlLink(stripslashes("$1"), stripslashes("$2"))', '#]*)\bsrc=([\'"])([^\'"]*?)\2\s([^>]*?)\s*(?:/?|>\n?#i' => "%apply=img $1$4%$3%%\n", '#(.*%apply=img\b[^%]+)\balign=([\'"]?)(l|r)(?:eft|ight)\2([^%]*%[^%]+)%%#i' => '%$3float% $1$4%%', '#(%apply=img\b[^%]+)\b(?:alt|title)=([\'"])([^\'"]+?)\2([^%]*%[^%]+)%%#i' => '$1$4"$3"%%', '#%apply=img\b(?:\s+(?:alt|title)=([\'"])\s*\1)*\s*%([^%]+)%%#' => '$2', '#]*)>#i' => '(:input form $1:)', '##i' => '(:input end:)', '#]*)\stype=([\'"]?)(\w+)\2([^>]*?)/?>#i' => '(:input $3$1$4:)', '#]*)>\s*(.*?)\s*#i' => '(:input textarea$1 value=\'$2\':)', '#]*)>(.*?)#ise' => 'preg_replace("!]*)>\s*(.*?)\s*!is","(:input select$1\$1 label=\"\$2\":)","$2")', "#$KeepToken(\d.*?H)$KeepToken#e" => "\$GLOBALS['KPV']['$1']" )); function ConvertHtmlLink($param, $txt) { $opt = array_change_key_case(ParseArgs($param), CASE_LOWER); if (empty($opt['href'])) return "$txt"; $link = "[[{$opt['href']}|$txt]]"; $ws = ''; foreach( array('target','rel','accesskey') as $p ) if (!empty($opt[$p])) $ws .= "$p=\"{$opt[$p]}\" "; if (empty($ws)) return $link; $ws = str_replace('target="_blank"', 'newwin', rtrim($ws, ' ')); return "%$ws%$link"; } function ConvertHtmlSpan($param) { return preg_replace( array( '/%/', '/(?:class|style)=([\'"])(.*?)\1/' ), array( 'pct', '$2' ), $param ); } function ConvertHtmlList($html) { $out = ''; $lit = array(); $strip = FALSE; $html = preg_replace('#(]+)>#i','$1>',$html); $lia = preg_split( '#\s*()\s*#i', $html, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); foreach( $lia as $n ) switch($n) { case '
    ': case '
      ': $lit[] = "\n".str_repeat( '*', count($lit)+1 ).' '; break; case '
        ': case '
          ': $lit[] = "\n".str_repeat( '#', count($lit)+1 ).' '; break; case '
    ': case '
': case '': case '': array_pop($lit); $strip = FALSE; break; case '
  • ': case '
  • ': if($lit) $out .= end($lit); $strip = TRUE; break; case '
  • ': case '': $strip = FALSE; break; default: if ($strip) { $out .= preg_replace('/\s+/',' ',$n); $strip = FALSE; } else $out .= $n; } return $out; }