diff --git a/.gitignore b/.gitignore index dab7be5..633e810 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -/.buildpath -/.project -/secret.php -/config.php +/.buildpath +/.project +/secret.php +/config.php +/test.php diff --git a/markdown.php b/markdown.php index b210d7b..0d90701 100644 --- a/markdown.php +++ b/markdown.php @@ -1,63 +1,84 @@ -'; - $lv ++; - } - while ( $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) { - $text .= $t; - } else { - $text .= '
  • ' . $t . '
  • '; - } - // var_dump ( $t ); - } - while ( $lv > 0 ) { - $text .= ''; - $lv --; - } - return $text; -} +'; + $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