diff --git a/index.php b/index.php index 6a02b41..1a05672 100644 --- a/index.php +++ b/index.php @@ -160,27 +160,29 @@ function translateGemToHtml($fileContents) { if (empty($line)) { echo "
\n"; } elseif ('^^^' == $line3) { - if (preg_match("/^\^\^\^\s+(.*)$/", $line)) { - $mode_textAttributes = !$mode_textAttributes; + $mode_textAttributes = !$mode_textAttributes; + } elseif ('^' == $line1 and !$mode_textAttributes_temp) { + if (preg_match("/^\^\s*(.+)$/", $line, $parts)) { + $line = $parts[1]; + $mode_textAttributes_temp = true; + } else { + $mode = "raw"; + } + continue; + } elseif ("#" == $line1) { + if (preg_match("/^(#{1,3})\s*(.+)/", $line, $sharps)) { + $h_level = strlen($sharps[1]); + $text = $sharps[2]; + htmlPrepare($text); + switch ($h_level) { + case 1: echo "
\n"; - } else { - echo "\n"; - } + preg_match("/^```\s*(.*)$/", $line, $matches); + $alt_text = trim($matches[1]); + if (empty($alt_text)) { + echo "\n"; + } else { + echo "\n"; } $mode="pre"; } elseif (">" == $line1) { - $mode = "quote"; - preg_match("/^>\s*(.*)$/", $line, $quoteParts); - $quote = $quoteParts[1]; echo "\n"; - if (empty($quote)) - echo "\n"; $mode = null; continue; } } elseif ("ul"==$mode) { - if ("* " == $line2) { + if ("*" == $line1) { preg_match("/^\*\s*(.*)$/", $line, $ulParts); $li = $ulParts[1]; if (empty($li)) { @@ -278,7 +280,7 @@ function translateGemToHtml($fileContents) { } } break; // exits the while(true) as no continue occured - } + } // while(true) } $html = ob_get_contents(); ob_clean();\n"; - else - htmlPrepare($quote); - if ($mode_textAttributes xor $mode_textAttributes_temp) addTextAttributes($line); - echo "
".$quote."
\n"; - } elseif ("* " == $line2) { + $mode = "quote"; + continue; + } elseif ("*" == $line1) { echo "\n"; $mode = "ul"; continue; @@ -230,9 +225,13 @@ function translateGemToHtml($fileContents) { } } else { if ("raw"==$mode) { - htmlPrepare($line); - if ($mode_textAttributes xor $mode_textAttributes_temp) addTextAttributes($line); - if (empty($line)) $line = " "; + if (empty($line)) { + $line = " "; + } else { + htmlPrepare($line); + if ($mode_textAttributes xor $mode_textAttributes_temp) + addTextAttributes($line); + } echo "
$line
\n"; $mode = null; } elseif ("pre"==$mode) { @@ -249,16 +248,19 @@ function translateGemToHtml($fileContents) { $quote = $quoteParts[1]; if (empty($quote)) echo "\n"; - else + else { htmlPrepare($quote); + if ($mode_textAttributes xor $mode_textAttributes_temp) + addTextAttributes($line); echo "
".$quote."
\n"; + } } else { echo "