");
foreach ($lines as $nline => $line) {
array_push($result, "
");
$header = FALSE;
if (0 < preg_match('/h$/i', $line)) {
$header = TRUE;
}
$elems = explode("|", $line);
foreach ($elems as $nelem => $elem) {
if ((0 == $nelem) || ($nelem == count($elems) - 1)) { continue; }
$tag = $header ? 'th' : 'td';
array_push($result, mwMikiApplyAttribute($tag, '', '', $elem));
}
array_push($result, "
");
}
array_push($result, "");
return join("", $result);
}
function mwMikiParseQuote($lines) {
$result = array();
array_push($result, "");
foreach ($lines as $line) {
array_push($result, preg_replace('/\>\s*(.+)/', '$1', $line));
}
array_push($result, "
");
return join("\n", $result);
}
function mwMikiParseUList($lines) {
$result = array();
array_push($result, '');
foreach ($lines as $line) {
array_push($result, preg_replace('/\-\s*(.+)/', '- $1
', $line));
}
array_push($result, "
");
return join("\n", $result);
}
function mwMikiParseOList($lines) {
$result = array();
array_push($result, '');
foreach ($lines as $line) {
array_push($result, preg_replace('/\+\s*(.+)/', '- $1
', $line));
}
array_push($result, "
");
return join("\n", $result);
}
function mwMikiParseDList($lines) {
$result = array();
array_push($result, "");
foreach ($lines as $line) {
$text = preg_replace('/\={1,2}\s*(.+)/', '$1', $line);
if (0 < preg_match('/^\=\=/', $line)) { // "== ..."
array_push($result, mwMikiApplyAttribute('dd', '', '', $text));
} else { // "= ..."
array_push($result, mwMikiApplyAttribute('dt', '', '', $text));
}
}
array_push($result, "
");
return join("\n", $result);
}
function mwMikiParseImage($line) {
// '/\(\(\s*(.+?)\s*>\s*(https?|ftp|news)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]*)\s*\)\)/',
// '/\(\(\s*(.+?)\s*>\s*([-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]*)\s*\)\)/',
if (0 < preg_match_all('/\(\(\s*(.+?)\s*>\s*([-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]*)\s*\)\)/', $line, $match)) {
for ($i = 0; $i < count($match[0]); $i++) {
$align = mwMikiCatchAlign($match[1][$i]);
$tag = '
';
if ($align == WP_MIKI_ALIGN_DEFAULT) {
$line = str_replace($match[0][$i], $tag, $line);
} else {
$ptag = '';
$line = str_replace($match[0][$i], $ptag, $line);
}
}
}
return $line;
}
function mwMikiParseMusic($line) {
$search = array(
'/\{\{\s*(.+?)\s*>\s*([-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]*)\s*\}\}/',
);
$replace = array(
WP_MIKI_MP3_PLAYER,
);
$line = preg_replace($search, $replace, $line);
return $line . "\n";
}
function mwMikiParseALink($line) {
$search = array(
// '/\[\[\s*(.+?)\s*>\s*(https?|ftp|news)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]*)\s*\]\]/',
'/\[\[\s*(.+?)\s*>\s*([-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]*)\s*\]\]/',
);
$replace = array(
// '$1',
'$1',
);
$line = preg_replace($search, $replace, $line);
return $line;
}
function mwMikiParse1Line($line) {
$line = mwMikiParseImage($line);
$line = mwMikiParseMusic($line);
$line = mwMikiParseALink($line);
$search = array(
'/%%(.+?)%%/',
'/\'\'\'(.+?)\'\'\'/',
'/\'\'(.+?)\'\'/',
'/\*\*\*\s*(.+)/',
'/\*\*\s*(.+)/',
'/\*\s*(.+)/',
'/^\/\/(.+)/',
);
$replace = array(
'$1',
'$1',
'$1',
'
$1
',
'$1
',
'$1
',
'',
);
$line = preg_replace($search, $replace, $line);
return $line;
}
function mwMikiDetectMode($line) {
if (trim($line) == "") { // empty line
return WP_MIKI_MODE_EMPTY;
}
switch ($line[0]) {
case '|': return WP_MIKI_MODE_TABLE;
case '>': return WP_MIKI_MODE_QUOTE;
case '-': return WP_MIKI_MODE_ULIST;
case '+': return WP_MIKI_MODE_OLIST;
case '=': return WP_MIKI_MODE_DLIST;
case ' ': return WP_MIKI_MODE_UMIKI;
default: return WP_MIKI_MODE_1LINE;
}
}
function mwMikiCatchAlign(& $text) {
$align = WP_MIKI_ALIGN_DEFAULT;
if (2 < strlen($text)) {
$prefix = substr($text, 0, 2);
switch ($prefix) {
case 'L:' : $align = WP_MIKI_ALIGN_LEFT; break;
case 'C:' : $align = WP_MIKI_ALIGN_CENTER; break;
case 'R:' : $align = WP_MIKI_ALIGN_RIGHT; break;
}
if ($align != WP_MIKI_ALIGN_DEFAULT) {
$text = preg_replace('/(L|C|R):\s*(.+)/', '$2', $text);
}
}
return $align;
}
function mwMikiApplyAttribute($tag, $attributes, $classes, $text) {
$align = mwMikiCatchAlign($text);
if ($align != WP_MIKI_ALIGN_DEFAULT) {
$attrc = '';
switch ($align) {
case WP_MIKI_ALIGN_LEFT: $attrc = 'miki_L'; break;
case WP_MIKI_ALIGN_CENTER: $attrc = 'miki_C'; break;
case WP_MIKI_ALIGN_RIGHT: $attrc = 'miki_R'; break;
}
$classes .= ' ' . $attrc;
}
if ($classes != "") {
$attributes .= ' class="' . trim($classes) . '"';
}
return '<' . $tag . ' ' . $attributes . '>' . $text . '' . $tag . '>';
}
?>