From 49dd8b113d8ec87390d244b1f6f694a698ba9927 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Sun, 27 Jan 2019 21:12:23 +0000 Subject: [PATCH] Make sure closing sequence is removed correctly --- src/Components/Blocks/Header.php | 7 ++++++- tests/commonmark/45-ATX_headings.html | 1 + tests/commonmark/45-ATX_headings.md | 1 + tests/commonmark/46-ATX_headings.html | 3 +++ tests/commonmark/46-ATX_headings.md | 3 +++ 5 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/commonmark/45-ATX_headings.html create mode 100644 tests/commonmark/45-ATX_headings.md create mode 100644 tests/commonmark/46-ATX_headings.html create mode 100644 tests/commonmark/46-ATX_headings.md diff --git a/src/Components/Blocks/Header.php b/src/Components/Blocks/Header.php index 3a50a66..615937d 100644 --- a/src/Components/Blocks/Header.php +++ b/src/Components/Blocks/Header.php @@ -68,7 +68,12 @@ final class Header implements Block $text = \trim($text, " \t"); # remove closing sequence - $text = \rtrim(\rtrim($text, '#'), " \t"); + $removedClosing = \rtrim($text, '#'); + $lastChar = \substr($removedClosing, -1, 1); + + if (\trim($lastChar, " \t") === '') { + $text = \rtrim($removedClosing, " \t"); + } return new self($text, $level); } diff --git a/tests/commonmark/45-ATX_headings.html b/tests/commonmark/45-ATX_headings.html new file mode 100644 index 0000000..3c9245b --- /dev/null +++ b/tests/commonmark/45-ATX_headings.html @@ -0,0 +1 @@ +

foo#

\ No newline at end of file diff --git a/tests/commonmark/45-ATX_headings.md b/tests/commonmark/45-ATX_headings.md new file mode 100644 index 0000000..5037128 --- /dev/null +++ b/tests/commonmark/45-ATX_headings.md @@ -0,0 +1 @@ +# foo# \ No newline at end of file diff --git a/tests/commonmark/46-ATX_headings.html b/tests/commonmark/46-ATX_headings.html new file mode 100644 index 0000000..43d06bd --- /dev/null +++ b/tests/commonmark/46-ATX_headings.html @@ -0,0 +1,3 @@ +

foo ###

+

foo ###

+

foo #

\ No newline at end of file diff --git a/tests/commonmark/46-ATX_headings.md b/tests/commonmark/46-ATX_headings.md new file mode 100644 index 0000000..a14fd9f --- /dev/null +++ b/tests/commonmark/46-ATX_headings.md @@ -0,0 +1,3 @@ +### foo \### +## foo #\## +# foo \# \ No newline at end of file