From 23000af64ee2e9a8f93393a69637735c6bef1bd0 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Thu, 24 Oct 2019 13:03:38 +0200 Subject: [PATCH] Add $singleLine param to Twig markdown parser This allows you to parse just a single line of Markdown, i.e. the parsed output won't include a HTML paragraph element. --- lib/Pico.php | 8 +++++--- lib/PicoTwigExtension.php | 9 +++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/Pico.php b/lib/Pico.php index c8c514a..0d327af 100644 --- a/lib/Pico.php +++ b/lib/Pico.php @@ -1650,13 +1650,15 @@ class Pico * @see Pico::substituteFileContent() * @see Pico::getFileContent() * - * @param string $markdown Markdown contents of a page + * @param string $markdown Markdown contents of a page + * @param bool $singleLine whether to parse just a single line of markup * * @return string parsed contents (HTML) */ - public function parseFileContent($markdown) + public function parseFileContent($markdown, $singleLine = false) { - return $this->getParsedown()->text($markdown); + $markdownParser = $this->getParsedown(); + return !$singleLine ? $markdownParser->text($markdown) : $markdownParser->line($markdown); } /** diff --git a/lib/PicoTwigExtension.php b/lib/PicoTwigExtension.php index c0861f7..f61c2c9 100644 --- a/lib/PicoTwigExtension.php +++ b/lib/PicoTwigExtension.php @@ -111,15 +111,16 @@ class PicoTwigExtension extends Twig_Extension * @see Pico::substituteFileContent() * @see Pico::parseFileContent() * - * @param string $markdown markdown to parse - * @param array $meta meta data to use for %meta.*% replacement + * @param string $markdown markdown to parse + * @param array $meta meta data to use for %meta.*% replacement + * @param bool $singleLine whether to parse just a single line of markup * * @return string parsed HTML */ - public function markdownFilter($markdown, array $meta = array()) + public function markdownFilter($markdown, array $meta = array(), $singleLine = false) { $markdown = $this->getPico()->substituteFileContent($markdown, $meta); - return $this->getPico()->parseFileContent($markdown); + return $this->getPico()->parseFileContent($markdown, $singleLine); } /**