From 93a3b610d6120508daa429df1e6bc09ac50d5b42 Mon Sep 17 00:00:00 2001 From: SilverServersCopiliot <111811784+SilverServersCopiliot@users.noreply.github.com> Date: Wed, 2 Aug 2023 14:39:26 -0700 Subject: [PATCH 1/3] Add image size support added the ability to set the size of an image in a backward compatible and optional way --- Parsedown.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Parsedown.php b/Parsedown.php index ae0cbdecd..3ef52172e 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -1378,6 +1378,12 @@ protected function inlineImage($Excerpt) ), ); + //get width and height from href attribute if exists (ex: "http://www.example.com/image.png#100x100") + if (preg_match('/^(.*)#(\d+)x(\d+)$/', $Link['element']['attributes']['href'], $matches)) { + if(isset($matches[2])) $Inline['element']['attributes']['width'] = $matches[2]; + if(isset($matches[3])) $Inline['element']['attributes']['height'] = $matches[3]; + } + $Inline['element']['attributes'] += $Link['element']['attributes']; unset($Inline['element']['attributes']['href']); From 67126e85ef48d4c67df0916b3911924e2cc90e3c Mon Sep 17 00:00:00 2001 From: SilverServersCopiliot <111811784+SilverServersCopiliot@users.noreply.github.com> Date: Fri, 4 Aug 2023 12:00:44 -0700 Subject: [PATCH 2/3] Add image sizing support Add image sizing support by allowing the following options: #[width]x[height] #[width]x #x[height] --- Parsedown.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Parsedown.php b/Parsedown.php index 3ef52172e..4269be098 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -1379,9 +1379,10 @@ protected function inlineImage($Excerpt) ); //get width and height from href attribute if exists (ex: "http://www.example.com/image.png#100x100") - if (preg_match('/^(.*)#(\d+)x(\d+)$/', $Link['element']['attributes']['href'], $matches)) { + if (preg_match('/^(.*)#(\d*)x(\d*)$/', $Link['element']['attributes']['href'], $matches)) { if(isset($matches[2])) $Inline['element']['attributes']['width'] = $matches[2]; if(isset($matches[3])) $Inline['element']['attributes']['height'] = $matches[3]; + $Inline['element']['attributes']['src'] = $matches[1]; } $Inline['element']['attributes'] += $Link['element']['attributes']; From 31eb54b2206c9d8322540fb9fd764b617554f19c Mon Sep 17 00:00:00 2001 From: SilverServersCopiliot <111811784+SilverServersCopiliot@users.noreply.github.com> Date: Fri, 4 Aug 2023 12:04:17 -0700 Subject: [PATCH 3/3] Update Parsedown.php --- Parsedown.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Parsedown.php b/Parsedown.php index 4269be098..820d51e13 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -1379,7 +1379,7 @@ protected function inlineImage($Excerpt) ); //get width and height from href attribute if exists (ex: "http://www.example.com/image.png#100x100") - if (preg_match('/^(.*)#(\d*)x(\d*)$/', $Link['element']['attributes']['href'], $matches)) { + if (!empty($Inline['element']['attributes']['src'])&&preg_match('/^(.*)#(\d*)x(\d*)$/', $Link['element']['attributes']['href'], $matches)) { if(isset($matches[2])) $Inline['element']['attributes']['width'] = $matches[2]; if(isset($matches[3])) $Inline['element']['attributes']['height'] = $matches[3]; $Inline['element']['attributes']['src'] = $matches[1];