diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-01-25 12:23:27 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-01-25 12:23:27 -0500 |
commit | 0812ceedde2f89a8e4b391e58d6463f832ecec8e (patch) | |
tree | 2653eb64866eae8bcf93c24a643b7d2b1110a060 /app/Core/Markdown.php | |
parent | e506648cbcda0b6021cf0a3b5e2f6381d8f1d0ea (diff) |
Merge fix #545, fix invalid HTML when linking to URLs with numeric fragment identifiers and update Parsedown
Diffstat (limited to 'app/Core/Markdown.php')
-rw-r--r-- | app/Core/Markdown.php | 43 |
1 files changed, 43 insertions, 0 deletions
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 @@ +<?php + +namespace Core; + +use Parsedown; + +/** + * Specific Markdown rules for Kanboard + * + * @package core + * @author norcnorc + * @author Frederic Guillot + */ +class Markdown extends Parsedown +{ + private $link; + private $helper; + + public function __construct($link, Helper $helper) + { + $this->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))); + } + } +} |