Merge fix #545, fix invalid HTML when linking to URLs with numeric fragment identifiers and update Parsedown
This commit is contained in:
parent
e506648cbc
commit
0812ceedde
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -18,8 +18,16 @@ class HelperTest extends Base
|
|||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<p>Task <a href="?controller=a&action=b&c=d&task_id=123" class="" title="" >#123</a></p>',
|
||||
'<p>Task <a href="?controller=a&action=b&c=d&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'))
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue