".$text[$i]."";
$i++;
$transcripted = true;
}
if(!$transcripted && preg_match("#^-(-)+$#", $text[$i+1])){
$converted .= "
".$text[$i]."
";
$i++;
$transcripted = true;
}
}
if(!$transcripted){
if(preg_match("#^\# (.)+$#", $text[$i])){
$converted .= preg_replace("#^\# (.+)$#", "$1
", $text[$i]);
$transcripted = true;
}
if(preg_match("#^\#\# (.)+$#", $text[$i])){
$converted .= preg_replace("#^\#\# (.+)$#", "$1
", $text[$i]);
$transcripted = true;
}
if(preg_match("#^\#\#\# (.)+$#", $text[$i])){
$converted .= preg_replace("#^\#\#\# (.+)$#", "$1
", $text[$i]);
$transcripted = true;
}
if(preg_match("#^\#\#\#\# (.)+$#", $text[$i])){
$converted .= preg_replace("#^\#\#\#\# (.+)$#", "$1
", $text[$i]);
$transcripted = true;
}
if(preg_match("#^\#\#\#\#\# (.)+$#", $text[$i])){
$converted .= preg_replace("#^\#\#\#\#\# (.+)$#", "$1
", $text[$i]);
$transcripted = true;
}
if(preg_match("#^\#\#\#\#\#\# (.)+$#", $text[$i])){
$converted .= preg_replace("#^\#\#\#\#\#\# (.+)$#", "$1
", $text[$i]);
$transcripted = true;
}
if(preg_match("#^---+$#", $text[$i])){
$converted .= preg_replace("#^---+$#", "
", $text[$i]);
$transcripted = true;
}
}
if(!$transcripted){
if(preg_match("#^[+*-] (.*)$#", $text[$i])){
$converted .= "";
while($i < count($text) && preg_match("#^[+*-] (.*)$#", $text[$i])){
$li = array(preg_replace("#^[+*-] (.*)$#", "$1", $text[$i]));
$i++;
while($i < count($text) && preg_match("#^\t+(.*)$#", $text[$i])){
$li[] = preg_replace("#^\t+(.*)$#", "$1", $text[$i]);
$i++;
}
$i--;
$converted .= "- ".convert($li)."
";
$i++;
}
$i--;
$converted .= "
";
$transcripted = true;
}
if(preg_match("#^1\. (.*)$#", $text[$i])){
$converted .= "";
while($i < count($text) && preg_match("#^[0-9]+\. (.*)$#", $text[$i])){
$li = array(preg_replace("#^[0-9]+\. (.*)$#", "$1", $text[$i]));
$i++;
while($i < count($text) && preg_match("#^\t+(.*)$#", $text[$i])){
$li[] = preg_replace("#^\t+(.*)$#", "$1", $text[$i]);
$i++;
}
$i--;
$converted .= "- ".convert($li)."
";
$i++;
}
$i--;
$converted .= "
";
$transcripted = true;
}
}
if(!$transcripted){
$text[$i] = preg_replace("#^(.*)\!\[(.*)\]\((.*)\)(.*)$#", "$1$4", $text[$i]);
$text[$i] = preg_replace("#^(.*)\[(.*)\]\((.*)\)(.*)$#", "$1$2$4", $text[$i]);
$text[$i] = preg_replace("#^(.*)\*\*(.+)\*\*(.*)$#", "$1$2$3", $text[$i]);
$text[$i] = preg_replace("#^(.*)\*(.+)\*(.*)$#", "$1$2$3", $text[$i]);
$text[$i] = preg_replace("#^(.*)(https?://[^ ]*[a-z])(.*)$#", "$1$2$3", $text[$i]);
$text[$i] = preg_replace("#^(.*)`(.*)`(.*)$#", "$1$2
$3", $text[$i]);
$converted .= $text[$i]."
";
}
}
return $converted;
}
function countIndentation($string){
$i = 0;
while($i < strlen($string) && $string[$i] == "\t") $i++;
return $i;
}
function md2html($text){
return convert(split($text));
}
echo md2html(file_get_contents("test.md"));
?>