diff --git a/_func.php b/_func.php index f37372f..9fdc381 100644 --- a/_func.php +++ b/_func.php @@ -6,5 +6,5 @@ include_once ('string.php'); include_once ('numbers.php'); include_once ('mail.php'); include_once ('debug.php'); -// include_once ('markdown.php'); +include_once ('markdown.php'); ?> \ No newline at end of file diff --git a/markdown.php b/markdown.php new file mode 100644 index 0000000..0d90701 --- /dev/null +++ b/markdown.php @@ -0,0 +1,84 @@ +'; + $lv = 0; + $str = explode ( "\n", str_replace ( "\r\n", "\n", $str ) ); + // var_dump ( $str ); + foreach ( $str as $t ) { + // echo '
' . $t . '
'; + $t = preg_replace_callback ( '/\[\[([^\]]*)\]\]/m', '_md_link_replacer', $t ); + $nlv = 0; + if (startsWith ( $t, '**** ' )) { + // echo - 1; + $t = substr ( $t, 5 ); + $nlv = 4; + } + if (startsWith ( $t, '*** ' )) { + // echo - 2; + $t = substr ( $t, 4 ); + $nlv = 3; + } + if (startsWith ( $t, '** ' )) { + // echo - 3; + $t = substr ( $t, 3 ); + $nlv = 2; + } + if (startsWith ( $t, '* ' )) { + // echo - 4; + $t = substr ( $t, 2 ); + $nlv = 1; + } + if ($lv != $nlv) { + while ( $lv < $nlv ) { + // echo '-5 (' . $lv . '-' . $nlv . ')'; + $text .= ''; + $lv --; + } + } + if (startsWith ( $t, '!!!!! ' )) { + $t = '
' . substr ( $t, 6 ) . '
'; + } + if (startsWith ( $t, '!!!! ' )) { + $t = '

' . substr ( $t, 5 ) . '

'; + } + if (startsWith ( $t, '!!! ' )) { + $t = '

' . substr ( $t, 4 ) . '

'; + } + if (startsWith ( $t, '!! ' )) { + $t = '

' . substr ( $t, 3 ) . '

'; + } + if (startsWith ( $t, '! ' )) { + $t = '

' . substr ( $t, 2 ) . '

'; + } + if ($lv == 0) { + if ($t == '') { + $text .= '

'; + } else { + $text .= $t; + } + } else { + $text .= '

  • ' . $t . '
  • '; + } + // var_dump ( $t ); + } + while ( $lv > 0 ) { + $text .= ''; + $lv --; + } + $text .= '

    '; + return $text; +} +function _md_link_replacer($in) { + // var_dump ( $in ); + $in = explode ( '|', $in [1], 2 ); + + return '' . (isset ( $in [1] ) ? $in [1] : $in [0]) . ''; +} +?> \ No newline at end of file