63 lines
1.4 KiB
PHP
63 lines
1.4 KiB
PHP
<?php
|
|
// TODO markdown imple
|
|
function md($str) {
|
|
return nl2br ( $str ); // TODO md problem
|
|
$text = '';
|
|
$lv = 0;
|
|
foreach ( explode ( "\n", $str ) as $t ) {
|
|
$nlv = 0;
|
|
if (startsWith ( '**** ', $t )) {
|
|
$t = substr ( $t, 5 );
|
|
$nlv = 4;
|
|
}
|
|
if (startsWith ( '*** ', $t )) {
|
|
$t = substr ( $t, 4 );
|
|
$nlv = 3;
|
|
}
|
|
if (startsWith ( '** ', $t )) {
|
|
$t = substr ( $t, 3 );
|
|
$nlv = 2;
|
|
}
|
|
if (startsWith ( '* ', $t )) {
|
|
$t = substr ( $t, 2 );
|
|
$nlv = 1;
|
|
}
|
|
if ($lv != $nlv) {
|
|
while ( $lv < $nlv ) {
|
|
$text .= '<ul>';
|
|
$lv ++;
|
|
}
|
|
while ( $lv > $nlv ) {
|
|
$text .= '</ul>';
|
|
$lv --;
|
|
}
|
|
}
|
|
if (startsWith ( $t, '!!!!! ' )) {
|
|
$t = '<h5>' . substr ( $t, 6 ) . '</h5>';
|
|
}
|
|
if (startsWith ( $t, '!!!! ' )) {
|
|
$t = '<h4>' . substr ( $t, 5 ) . '</h4>';
|
|
}
|
|
if (startsWith ( $t, '!!! ' )) {
|
|
$t = '<h3>' . substr ( $t, 4 ) . '</h3>';
|
|
}
|
|
if (startsWith ( $t, '!! ' )) {
|
|
$t = '<h2>' . substr ( $t, 3 ) . '</h2>';
|
|
}
|
|
if (startsWith ( $t, '! ' )) {
|
|
$t = '<h1>' . substr ( $t, 2 ) . '</h1>';
|
|
}
|
|
if ($lv == 0) {
|
|
$text .= $t;
|
|
} else {
|
|
$text .= '<li>' . $t . '</li>';
|
|
}
|
|
// var_dump ( $t );
|
|
}
|
|
while ( $lv > 0 ) {
|
|
$text .= '</ul>';
|
|
$lv --;
|
|
}
|
|
return $text;
|
|
}
|
|
?>
|