diff --git a/app/Core/Markdown.php b/app/Core/Markdown.php index 2a866cf25..beb8ec258 100644 --- a/app/Core/Markdown.php +++ b/app/Core/Markdown.php @@ -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 * diff --git a/tests/units/Helper/TextHelperTest.php b/tests/units/Helper/TextHelperTest.php index c010094aa..0bd02e879 100644 --- a/tests/units/Helper/TextHelperTest.php +++ b/tests/units/Helper/TextHelperTest.php @@ -29,6 +29,16 @@ class TextHelperTest extends Base $this->assertEquals('
Test
', $textHelper->markdown('Test')); + $this->assertEquals( + '#123', + $textHelper->markdown('#123') + ); + + $this->assertEquals( + "Task #123
\nTask #123
', $textHelper->markdown('Task #123')