diff --git a/Parsedown.php b/Parsedown.php index ebc8097..95a51f8 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -86,6 +86,44 @@ class Parsedown return $text; } + function highlight($text, $language = '') + { + if (is_array($text) and isset($text['text'])) + { + if (isset($text['language'])) + $language = $text['language']; + $text = $text['text']; + } + + switch ($language) + { + case 'php': + if (strpos($text, '<'.'?') === false) + { + $text = '<'.'?php'."\n".$text; + $tag_added = true; + } + + $markup = '
'.highlight_string($text, true).''."\n"; + + if (isset($tag_added)) + { + $markup = preg_replace('@<\?php
'."\n";
+ }
+
+ return $markup;
+ }
+
#
# Private
@@ -670,25 +708,18 @@ class Parsedown
break;
case 'code':
-
- $text = htmlspecialchars($block['text'], ENT_NOQUOTES, 'UTF-8');
-
- $markup .= ''.$text.'
'."\n";
-
- break;
-
case 'fenced':
- $text = htmlspecialchars($block['text'], ENT_NOQUOTES, 'UTF-8');
-
- $markup .= 'highlight($block);
}
+ else
+ {
+ $text = htmlspecialchars($block['text'], ENT_NOQUOTES, 'UTF-8');
- $markup .= '>'.$text.'
'."\n";
+ $markup .= ''.$text.'
'."\n";
+ }
break;