From 543112f89e26773f239fbf28cdfe7eb6ab571c71 Mon Sep 17 00:00:00 2001 From: Michael Ochmann Date: Tue, 23 Aug 2022 15:18:56 +0200 Subject: [PATCH] added better debug tools in strict mode * assertion errors can now be opened in vscode --- index.php | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index 8ae972a..79e7a64 100644 --- a/index.php +++ b/index.php @@ -3,7 +3,6 @@ require __DIR__."/vendor/autoload.php"; -$source = file_get_contents(dirname(__FILE__)."/README.md"); echo " "; -$Instance = new parkdown\Parkdown($source); -echo $Instance->html(); \ No newline at end of file +$file = dirname(__FILE__)."/README.md"; +$source = file_get_contents($file); + +try { + $Instance = new parkdown\Parkdown($source, true, $file); + echo $Instance->html(); +} catch (AssertionError $error) { + echo "
";
+
+	$message  = explode(" ", $error->getMessage());
+	$location = array_shift($message);
+	$file     = explode(":", $location)[0];
+
+	if ($file === "INPUT_STRING")
+		echo "$location ".implode(" ", $message);
+	else
+		echo "$location ".implode(" ", $message);
+
+	
+	$stackTrace = explode("\n", $error->getTraceAsString());
+	array_shift($stackTrace);
+
+	echo "

"; + foreach ($stackTrace as $step) { + $step = explode(" ", $step); + array_shift($step); + $location = array_shift($step); + $location = preg_replace("/\(([0-9]+)\):/", ":\$1:", $location); + + echo "$location ".implode(" ", $step)."
"; + } + echo "

"; +} \ No newline at end of file