Add support for task links in Markdown headings
If a text block matches #(\d+) it will be interpreted as a task link instead of a heading. Closes #5017
This commit is contained in:
committed by
Frédéric Guillot
parent
e06c6656bc
commit
d3f38d1bf2
@@ -41,11 +41,33 @@ class Markdown extends Parsedown
|
||||
{
|
||||
$this->isPublicLink = $isPublicLink;
|
||||
$this->container = $container;
|
||||
$this->BlockTypes['#'][0] = 'CustomHeader';
|
||||
$this->InlineTypes['#'][] = 'TaskLink';
|
||||
$this->InlineTypes['@'][] = 'UserLink';
|
||||
$this->inlineMarkerList .= '#@';
|
||||
}
|
||||
|
||||
protected function blockCustomHeader($Line)
|
||||
{
|
||||
if (preg_match('!#(\d+)!i', $Line['text'], $matches))
|
||||
{
|
||||
$link = $this->buildTaskLink($matches[1]);
|
||||
|
||||
if (! empty($link)) {
|
||||
return [
|
||||
'extent' => strlen($matches[0]),
|
||||
'element' => [
|
||||
'name' => 'a',
|
||||
'text' => $matches[0],
|
||||
'attributes' => ['href' => $link],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->blockHeader($Line);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Task Links
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user