summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Core/Helper.php22
-rw-r--r--app/Core/Markdown.php43
-rw-r--r--composer.json2
-rw-r--r--composer.lock12
-rw-r--r--tests/units/HelperTest.php10
5 files changed, 62 insertions, 27 deletions
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 @@
+<?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)));
+ }
+ }
+}
diff --git a/composer.json b/composer.json
index 537aed86..c35d5243 100644
--- a/composer.json
+++ b/composer.json
@@ -5,7 +5,7 @@
"swiftmailer/swiftmailer": "@stable",
"fguillot/json-rpc": "0.0.1",
"fguillot/picodb": "0.0.2",
- "erusev/parsedown": "1.1.1",
+ "erusev/parsedown": "1.5.1",
"lusitanian/oauth": "0.3.5",
"pimple/pimple": "~3.0",
"symfony/console": "@stable",
diff --git a/composer.lock b/composer.lock
index 3091ab74..06e31689 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,20 +4,20 @@
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "hash": "a5f10d6c565a2a7b5b63650d550cabf2",
+ "hash": "671bd4694072aed17a542db8f08db217",
"packages": [
{
"name": "erusev/parsedown",
- "version": "1.1.1",
+ "version": "1.5.1",
"source": {
"type": "git",
"url": "https://github.com/erusev/parsedown.git",
- "reference": "da5d75e97e1ed19e57bd54fa6cb595a6a0879a67"
+ "reference": "9da19c1108c39df9b42adc42e39b8371070652d0"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/erusev/parsedown/zipball/da5d75e97e1ed19e57bd54fa6cb595a6a0879a67",
- "reference": "da5d75e97e1ed19e57bd54fa6cb595a6a0879a67",
+ "url": "https://api.github.com/repos/erusev/parsedown/zipball/9da19c1108c39df9b42adc42e39b8371070652d0",
+ "reference": "9da19c1108c39df9b42adc42e39b8371070652d0",
"shasum": ""
},
"type": "library",
@@ -43,7 +43,7 @@
"markdown",
"parser"
],
- "time": "2014-10-29 20:29:46"
+ "time": "2015-01-24 13:01:47"
},
{
"name": "fguillot/json-rpc",
diff --git a/tests/units/HelperTest.php b/tests/units/HelperTest.php
index 2ae75684..8694e8a2 100644
--- a/tests/units/HelperTest.php
+++ b/tests/units/HelperTest.php
@@ -18,8 +18,16 @@ class HelperTest extends Base
);
$this->assertEquals(
- '<p>Task <a href="?controller=a&amp;action=b&amp;c=d&amp;task_id=123" class="" title="" >#123</a></p>',
+ '<p>Task <a href="?controller=a&amp;action=b&amp;c=d&amp;task_id=123">#123</a></p>',
$h->markdown('Task #123', array('controller' => 'a', 'action' => 'b', 'params' => array('c' => 'd')))
);
+
+ $this->assertEquals(
+ '<p>Check that: <a href="http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454">http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454</a></p>',
+ $h->markdown(
+ 'Check that: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454',
+ array('controller' => 'a', 'action' => 'b', 'params' => array('c' => 'd'))
+ )
+ );
}
}