From 55eaa1d7b47d11078bd441427cfe16483cf966f7 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Mon, 21 Jun 2021 18:40:06 +0200 Subject: Add function getMarkdownImageURLs --- core/functions.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/functions.php b/core/functions.php index 7157e03..4befb19 100644 --- a/core/functions.php +++ b/core/functions.php @@ -185,6 +185,20 @@ function parseEntityContent(Item $Item): string { return $Parsedown->text($text); } +#=============================================================================== +# Extract Markdown formatted image URLs +#=============================================================================== +function getMarkdownImageURLs(string $text): array { + $pattern = '#\!\[(.*)\][ ]?(?:\n[ ]*)?\((.*)(\s[\'"](.*)[\'"])?\)#U'; + $content = parseContentTags($text); + + if(preg_match_all($pattern, $content, $matches)) { + return array_map('htmlentities', $matches[2]); + } + + return []; +} + #=============================================================================== # Parser for datetime formatted strings [YYYY-MM-DD HH:II:SS] #=============================================================================== -- cgit v1.2.3