From 6f8c0e3cb62ad429f409b723664be18987f4fbd5 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Sun, 26 Jul 2020 21:06:33 +0200 Subject: [PATCH] disable headings in markdown (#1843) --- UPGRADING.md | 1 + src/Utils/ParsedownExtension.php | 30 ++++++++++++++++++++++++++++ tests/Twig/MarkdownExtensionTest.php | 2 +- tests/Utils/MarkdownTest.php | 18 ++++++++--------- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/UPGRADING.md b/UPGRADING.md index 134ef429..b9725d3d 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -16,6 +16,7 @@ Perform EACH version specific task between your version and the new one, otherwi - Sessions are now stored in the database (all users have to re-login after upgrade) - New permissions: `lockdown_grace_timesheet`, `lockdown_override_timesheet`, `view_all_data` - Fixed team permissions on user queries: depending on your previous team & permission setup your users might see less data (SUPER_ADMINS see all data, but new: ADMINS only see all data if they own the `view_all_data` permission) +- Markdown does not support headings any more, text like `# foo` is not converted to `

foo

` anymore ### Developer diff --git a/src/Utils/ParsedownExtension.php b/src/Utils/ParsedownExtension.php index 0c54b78f..1589856e 100644 --- a/src/Utils/ParsedownExtension.php +++ b/src/Utils/ParsedownExtension.php @@ -16,6 +16,36 @@ class ParsedownExtension extends \Parsedown { private $ids = []; + /** + * Overwritten to prevent # to show up as headings for two reasons: + * - Hashes are often used to cross link issues in other systems + * - Headings should not occur in time record listings + */ + protected $BlockTypes = [ + '*' => ['Rule', 'List'], + '+' => ['List'], + '-' => ['SetextHeader', 'Table', 'Rule', 'List'], + '0' => ['List'], + '1' => ['List'], + '2' => ['List'], + '3' => ['List'], + '4' => ['List'], + '5' => ['List'], + '6' => ['List'], + '7' => ['List'], + '8' => ['List'], + '9' => ['List'], + ':' => ['Table'], + '<' => ['Comment', 'Markup'], + '=' => ['SetextHeader'], + '>' => ['Quote'], + '[' => ['Reference'], + '_' => ['Rule'], + '`' => ['FencedCode'], + '|' => ['Table'], + '~' => ['FencedCode'], + ]; + /** * Overwritten to add support for file:/// */ diff --git a/tests/Twig/MarkdownExtensionTest.php b/tests/Twig/MarkdownExtensionTest.php index 945eed22..508c4f1f 100644 --- a/tests/Twig/MarkdownExtensionTest.php +++ b/tests/Twig/MarkdownExtensionTest.php @@ -38,7 +38,7 @@ class MarkdownExtensionTest extends TestCase $config = new TimesheetConfiguration($loader, ['markdown_content' => true]); $sut = new MarkdownExtension(new Markdown(), $config); $this->assertEquals('

test

', $sut->markdownToHtml('*test*')); - $this->assertEquals('

foobar

', $sut->markdownToHtml('# foobar')); + $this->assertEquals('

# foobar

', $sut->markdownToHtml('# foobar')); } public function testTimesheetContent() diff --git a/tests/Utils/MarkdownTest.php b/tests/Utils/MarkdownTest.php index 2e8a6acf..5871a5b9 100644 --- a/tests/Utils/MarkdownTest.php +++ b/tests/Utils/MarkdownTest.php @@ -22,21 +22,21 @@ class MarkdownTest extends TestCase { $sut = new Markdown(); $this->assertEquals('

test

', $sut->toHtml('*test*')); - $this->assertEquals('

foobar

', $sut->toHtml('# foobar')); + $this->assertEquals('

# foobar

', $sut->toHtml('# foobar')); $html = <<<'EOT'

foo bar

-

test

-

asdfasdfa

+

# test
+asdfasdfa

ssdfsdf

http://example.com/foo-bar.html
file:///home/kimai/images/beautiful-flower.png

sdfsdf asdfasdf asdfasdf

-

test

-

aasdfasdf
+

# test
+aasdfasdf
1111
222

EOT; @@ -70,10 +70,10 @@ EOT; $sut = new Markdown(); $html = <<<'EOT' -

test

-

test

-

test

-

test

+

# test
+## test
+### test
+# test

EOT; $markdown = <<