2015-02-25 17:29:06 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Core;
|
|
|
|
|
|
|
|
use Parsedown;
|
2015-08-16 17:04:56 +02:00
|
|
|
use Helper\Url;
|
2015-02-25 17:29:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Specific Markdown rules for Kanboard
|
|
|
|
*
|
|
|
|
* @package core
|
|
|
|
* @author norcnorc
|
|
|
|
* @author Frederic Guillot
|
|
|
|
*/
|
|
|
|
class Markdown extends Parsedown
|
|
|
|
{
|
|
|
|
private $link;
|
|
|
|
private $helper;
|
2015-08-16 17:04:56 +02:00
|
|
|
|
|
|
|
public function __construct($link, Url $helper)
|
2015-02-25 17:29:06 +01:00
|
|
|
{
|
|
|
|
$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)) {
|
|
|
|
|
2015-08-16 17:04:56 +02:00
|
|
|
$url = $this->helper->href(
|
|
|
|
$this->link['controller'],
|
|
|
|
$this->link['action'],
|
|
|
|
$this->link['params'] + array('task_id' => $matches[1])
|
|
|
|
);
|
|
|
|
|
2015-02-25 17:29:06 +01:00
|
|
|
return array(
|
|
|
|
'extent' => strlen($matches[0]),
|
|
|
|
'element' => array(
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => $matches[0],
|
|
|
|
'attributes' => array('href' => $url)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|