From 0812ceedde2f89a8e4b391e58d6463f832ecec8e Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 25 Jan 2015 12:23:27 -0500 Subject: Merge fix #545, fix invalid HTML when linking to URLs with numeric fragment identifiers and update Parsedown --- app/Core/Helper.php | 22 +++------------------- app/Core/Markdown.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 app/Core/Markdown.php (limited to 'app') diff --git a/app/Core/Helper.php b/app/Core/Helper.php index dbe5a271..0b267797 100644 --- a/app/Core/Helper.php +++ b/app/Core/Helper.php @@ -3,7 +3,6 @@ namespace Core; use Pimple\Container; -use Parsedown; /** * Template helpers @@ -474,24 +473,9 @@ class Helper */ public function markdown($text, array $link = array()) { - $html = Parsedown::instance() - ->setMarkupEscaped(true) # escapes markup (HTML) - ->text($text); - - // Replace task #123 by a link to the task - if (! empty($link) && preg_match_all('!#(\d+)!i', $html, $matches, PREG_SET_ORDER)) { - - foreach ($matches as $match) { - - $html = str_replace( - $match[0], - $this->a($match[0], $link['controller'], $link['action'], $link['params'] + array('task_id' => $match[1])), - $html - ); - } - } - - return $html; + $parser = new Markdown($link, $this); + $parser->setMarkupEscaped(true); + return $parser->text($text); } /** diff --git a/app/Core/Markdown.php b/app/Core/Markdown.php new file mode 100644 index 00000000..3dd98617 --- /dev/null +++ b/app/Core/Markdown.php @@ -0,0 +1,43 @@ +link = $link; + $this->helper = $helper; + $this->InlineTypes['#'][] = 'TaskLink'; + $this->inlineMarkerList .= '#'; + } + + protected function inlineTaskLink($Excerpt) + { + // Replace task #123 by a link to the task + if (! empty($this->link) && preg_match('!#(\d+)!i', $Excerpt['text'], $matches)) { + + $url = $this->helper->u($this->link['controller'], + $this->link['action'], + $this->link['params'] + array('task_id' => $matches[1])); + return array( + 'extent' => strlen($matches[0]), + 'element' => array( + 'name' => 'a', + 'text' => $matches[0], + 'attributes' => array('href' => $url))); + } + } +} -- cgit v1.2.3