This commit is contained in:
stitz 2020-02-11 15:47:28 +01:00
parent 555240506b
commit fb9b2cc6e2

View File

@ -1,6 +1,62 @@
<?php
// TODO markdown imple
function decode_md($str) {
return $str;
}
<?php
// TODO markdown imple
function md($str) {
$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;
}
?>