md
This commit is contained in:
parent
555240506b
commit
fb9b2cc6e2
66
markdown.php
66
markdown.php
@ -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;
|
||||
}
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user