From 1b15e9374482de4fea434600034e1f4f968ee338 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sun, 2 Jul 2023 11:07:29 +0200 Subject: [PATCH 01/10] Update kitchen-sink --- tests/stubs/kitchen-sink.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/stubs/kitchen-sink.md b/tests/stubs/kitchen-sink.md index 2ec39c7..dec345d 100644 --- a/tests/stubs/kitchen-sink.md +++ b/tests/stubs/kitchen-sink.md @@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [ ] Task 1 - [x] Task 2 +## Curiosities + +- This is a list item which is followed by an indented content on the next line + which is part of the same list item + ## [Unreleased](https://github.com/olivierlacan/keep-a-changelog/compare/v1.0.0...HEAD) ## [1.0.0](https://github.com/olivierlacan/keep-a-changelog/compare/v0.3.0...v1.0.0) - 2017-06-20 From e8fa8943a0624814ab2862fa853eb219ed32f4fd Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sun, 2 Jul 2023 11:17:09 +0200 Subject: [PATCH 02/10] Add potential fix --- src/Renderer/Block/ListItemRenderer.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Renderer/Block/ListItemRenderer.php b/src/Renderer/Block/ListItemRenderer.php index cbceb3d..783d50e 100644 --- a/src/Renderer/Block/ListItemRenderer.php +++ b/src/Renderer/Block/ListItemRenderer.php @@ -24,6 +24,13 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer): s ListItem::assertInstanceOf($node); $contents = $childRenderer->renderNodes($node->children()); + + /** + if (str_contains($contents, "\n")) { + $contents = str_replace("\n", " ", $contents); + } + */ + if (str_starts_with($contents, '<') && ! $this->startsTaskListItem($node)) { $contents = "\n" . $contents; } From 827fb27ac4af32afa0f41156cf81031d942bee1d Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Wed, 26 Jul 2023 20:27:36 +0200 Subject: [PATCH 03/10] Simplify kitchen-sink --- tests/stubs/kitchen-sink.md | 170 ++---------------------------------- 1 file changed, 7 insertions(+), 163 deletions(-) diff --git a/tests/stubs/kitchen-sink.md b/tests/stubs/kitchen-sink.md index dec345d..4986ba6 100644 --- a/tests/stubs/kitchen-sink.md +++ b/tests/stubs/kitchen-sink.md @@ -1,9 +1,7 @@ # Changelog All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Task List @@ -17,165 +15,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/olivierlacan/keep-a-changelog/compare/v1.0.0...HEAD) -## [1.0.0](https://github.com/olivierlacan/keep-a-changelog/compare/v0.3.0...v1.0.0) - 2017-06-20 - -### Added - -- New visual identity by [@tylerfortune8](https://github.com/tylerfortune8). -- Version navigation. -- Links to latest released version in previous versions. -- "Why keep a changelog?" section. -- "Who needs a changelog?" section. -- "How do I make a changelog?" section. -- "Frequently Asked Questions" section. -- New "Guiding Principles" sub-section to "How do I make a changelog?". -- Simplified and Traditional Chinese translations from [@tianshuo](https://github.com/tianshuo). -- German translation from [@mpbzh](https://github.com/mpbzh) & [@Art4](https://github.com/Art4). -- Italian translation from [@azkidenz](https://github.com/azkidenz). -- Swedish translation from [@magol](https://github.com/magol). -- Turkish translation from [@karalamalar](https://github.com/karalamalar). -- French translation from [@zapashcanon](https://github.com/zapashcanon). -- Brazilian Portugese translation from [@Webysther](https://github.com/Webysther). -- Polish translation from [@amielucha](https://github.com/amielucha) & [@m-aciek](https://github.com/m-aciek). -- Russian translation from [@aishek](https://github.com/aishek). -- Czech translation from [@h4vry](https://github.com/h4vry). -- Slovak translation from [@jkostolansky](https://github.com/jkostolansky). -- Korean translation from [@pierceh89](https://github.com/pierceh89). -- Croatian translation from [@porx](https://github.com/porx). -- Persian translation from [@Hameds](https://github.com/Hameds). -- Ukrainian translation from [@osadchyi-s](https://github.com/osadchyi-s). - -### Changed - -- Start using "changelog" over "change log" since it's the common usage. -- Start versioning based on the current English version at 0.3.0 to help -- translation authors keep things up-to-date. -- Rewrite "What makes unicorns cry?" section. -- Rewrite "Ignoring Deprecations" sub-section to clarify the ideal -- scenario. -- Improve "Commit log diffs" sub-section to further argument against -- them. -- Merge "Why can’t people just use a git log diff?" with "Commit log -- diffs" -- Fix typos in Simplified Chinese and Traditional Chinese translations. -- Fix typos in Brazilian Portuguese translation. -- Fix typos in Turkish translation. -- Fix typos in Czech translation. -- Fix typos in Swedish translation. -- Improve phrasing in French translation. -- Fix phrasing and spelling in German translation. - -### Removed - -- Section about "changelog" vs "CHANGELOG". - -## [0.3.0](https://github.com/olivierlacan/keep-a-changelog/compare/v0.2.0...v0.3.0) - 2015-12-03 - -### Added - -- RU translation from [@aishek](https://github.com/aishek). -- pt-BR translation from [@tallesl](https://github.com/tallesl). -- es-ES translation from [@ZeliosAriex](https://github.com/ZeliosAriex). - -## [0.2.0](https://github.com/olivierlacan/keep-a-changelog/compare/v0.1.0...v0.2.0) - 2015-10-06 - -### Changed - -- Remove exclusionary mentions of "open source" since this project can -- benefit both "open" and "closed" source projects equally. - -## [0.1.0](https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.8...v0.1.0) - 2015-10-06 - -### Added - -- Answer "Should you ever rewrite a change log?". - -### Changed - -- Improve argument against commit logs. -- Start following [SemVer](https://semver.org) properly. - -## [0.0.8](https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.7...v0.0.8) - 2015-02-17 - -### Changed - -- Update year to match in every README example. -- Reluctantly stop making fun of Brits only, since most of the world -- writes dates in a strange way. - -### Fixed - -- Fix typos in recent README changes. -- Update outdated unreleased diff link. - -## [0.0.7](https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.6...v0.0.7) - 2015-02-16 - -### Added - -- Link, and make it obvious that date format is ISO 8601. - -### Changed - -- Clarified the section on "Is there a standard change log format?". - -### Fixed - -- Fix Markdown links to tag comparison URL with footnote-style links. - -## [0.0.6](https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.5...v0.0.6) - 2014-12-12 - -### Added - -- README section on "yanked" releases. - -## [0.0.5](https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.4...v0.0.5) - 2014-08-09 - -### Added - -- Markdown links to version tags on release headings. -- Unreleased section to gather unreleased changes and encourage note -- keeping prior to releases. - -## [0.0.4](https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.3...v0.0.4) - 2014-08-09 - -### Added - -- Better explanation of the difference between the file ("CHANGELOG") -- and its function "the change log". - -### Changed - -- Refer to a "change log" instead of a "CHANGELOG" throughout the site -- to differentiate between the file and the purpose of the file — the -- logging of changes. - -### Removed - -- Remove empty sections from CHANGELOG, they occupy too much space and -- create too much noise in the file. People will have to assume that the -- missing sections were intentionally left out because they contained no -- notable changes. - -## [0.0.3](https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.2...v0.0.3) - 2014-08-09 - -### Added - -- "Why should I care?" section mentioning The Changelog podcast. - -## [0.0.2](https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.1...v0.0.2) - 2014-07-10 - -### Added - -- Explanation of the recommended reverse chronological release ordering. - -## [0.0.1](https://github.com/olivierlacan/keep-a-changelog/releases/tag/v0.0.1) - 2014-05-31 +**This Text is Bold** +_This Text is Italic_ -### Added +`\Class->getFoo()` -- This CHANGELOG file to hopefully serve as an evolving example of a -- standardized open source project CHANGELOG. -- CNAME file to enable GitHub Pages custom domain -- README now contains answers to common questions about CHANGELOGs -- Good examples and basic guidelines, including proper date formatting. -- Counter-examples: "What makes unicorns cry?" -- `\Class->getFoo()` +``` +Hello World +``` From 9f15aa5bf5238e29e033473ed1d3ee8fac9ccbfa Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Wed, 26 Jul 2023 20:33:43 +0200 Subject: [PATCH 04/10] Add kitchen-sink-expected.md --- tests/Renderer/MarkdownRendererTest.php | 3 ++- tests/stubs/kitchen-sink-expected.md | 21 +++++++++++++++++++++ tests/stubs/kitchen-sink.md | 6 +----- 3 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 tests/stubs/kitchen-sink-expected.md diff --git a/tests/Renderer/MarkdownRendererTest.php b/tests/Renderer/MarkdownRendererTest.php index 89a252f..51212a7 100644 --- a/tests/Renderer/MarkdownRendererTest.php +++ b/tests/Renderer/MarkdownRendererTest.php @@ -41,11 +41,12 @@ public function it_renders_ast_to_markdown(): void public function it_parses_and_renders_kitchen_sink(): void { $contentKitchenSink = file_get_contents(__DIR__ . '/../stubs/kitchen-sink.md'); + $contentKitchenSinkExpected = file_get_contents(__DIR__ . '/../stubs/kitchen-sink-expected.md'); $document = $this->parser->parse($contentKitchenSink); $result = $this->renderer->renderDocument($document)->getContent(); - $this->assertEquals($contentKitchenSink, $result); + $this->assertEquals($contentKitchenSinkExpected, $result); } } diff --git a/tests/stubs/kitchen-sink-expected.md b/tests/stubs/kitchen-sink-expected.md new file mode 100644 index 0000000..f59041f --- /dev/null +++ b/tests/stubs/kitchen-sink-expected.md @@ -0,0 +1,21 @@ +# Changelog + +All notable changes to this project will be documented in this file. +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). + +## Task List + +- [ ] Task 1 +- [x] Task 2 + +## Curiosities + +- This is a list item which is followed by an indented content on the next line +- which is part of the same list item + +## [Unreleased](https://github.com/olivierlacan/keep-a-changelog/compare/v1.0.0...HEAD) + +**This Text is Bold** +*This Text is Italic* + +`\Class->getFoo()` diff --git a/tests/stubs/kitchen-sink.md b/tests/stubs/kitchen-sink.md index 4986ba6..adf44fc 100644 --- a/tests/stubs/kitchen-sink.md +++ b/tests/stubs/kitchen-sink.md @@ -16,10 +16,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased](https://github.com/olivierlacan/keep-a-changelog/compare/v1.0.0...HEAD) **This Text is Bold** -_This Text is Italic_ +*This Text is Italic* `\Class->getFoo()` - -``` -Hello World -``` From d18be3e6fac9fca9361b00e8b6c0ffbebfad1f40 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 29 Jul 2023 11:03:35 +0200 Subject: [PATCH 05/10] Update KitchenSink --- tests/stubs/kitchen-sink-expected.md | 6 ++++-- tests/stubs/kitchen-sink.md | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/stubs/kitchen-sink-expected.md b/tests/stubs/kitchen-sink-expected.md index f59041f..51c7c8f 100644 --- a/tests/stubs/kitchen-sink-expected.md +++ b/tests/stubs/kitchen-sink-expected.md @@ -10,8 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Curiosities -- This is a list item which is followed by an indented content on the next line -- which is part of the same list item +- This is a list item which is followed by an indented content on the next line which is part of the same list item +- This is a list item which contains multiple paragraphs + This is the second paragraph. + This is the third paragraph. ## [Unreleased](https://github.com/olivierlacan/keep-a-changelog/compare/v1.0.0...HEAD) diff --git a/tests/stubs/kitchen-sink.md b/tests/stubs/kitchen-sink.md index adf44fc..51a41d6 100644 --- a/tests/stubs/kitchen-sink.md +++ b/tests/stubs/kitchen-sink.md @@ -12,6 +12,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - This is a list item which is followed by an indented content on the next line which is part of the same list item +- This is a list item which contains multiple paragraphs + This is the second paragraph. + This is the third paragraph. ## [Unreleased](https://github.com/olivierlacan/keep-a-changelog/compare/v1.0.0...HEAD) From cbb1522092fa57d222f16c7f93b7ba26d99690bc Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sun, 30 Jul 2023 10:20:12 +0200 Subject: [PATCH 06/10] Update Tests --- tests/Renderer/MarkdownRendererTest.php | 16 ++++++++++++++++ tests/stubs/kitchen-sink-expected.md | 13 +++++++------ tests/stubs/kitchen-sink.md | 12 ++++++------ 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/tests/Renderer/MarkdownRendererTest.php b/tests/Renderer/MarkdownRendererTest.php index 51212a7..e54a44e 100644 --- a/tests/Renderer/MarkdownRendererTest.php +++ b/tests/Renderer/MarkdownRendererTest.php @@ -49,4 +49,20 @@ public function it_parses_and_renders_kitchen_sink(): void $this->assertEquals($contentKitchenSinkExpected, $result); } + + #[Test] + public function it_parses_kitchen_sink_and_parsing_the_result_again_returns_the_same_result(): void + { + $contentKitchenSink = file_get_contents(__DIR__ . '/../stubs/kitchen-sink.md'); + $contentKitchenSinkExpected = file_get_contents(__DIR__ . '/../stubs/kitchen-sink-expected.md'); + + $document = $this->parser->parse($contentKitchenSink); + + $result = $this->renderer->renderDocument($document)->getContent(); + // $this->assertEquals($contentKitchenSinkExpected, $result); + + $document = $this->parser->parse($result); + $result = $this->renderer->renderDocument($document)->getContent(); + $this->assertEquals($contentKitchenSinkExpected, $result); + } } diff --git a/tests/stubs/kitchen-sink-expected.md b/tests/stubs/kitchen-sink-expected.md index 51c7c8f..5b312fc 100644 --- a/tests/stubs/kitchen-sink-expected.md +++ b/tests/stubs/kitchen-sink-expected.md @@ -3,18 +3,19 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). -## Task List - -- [ ] Task 1 -- [x] Task 2 - ## Curiosities -- This is a list item which is followed by an indented content on the next line which is part of the same list item +- This is a list item which is followed by an indented content on the next line + which is part of the same list item - This is a list item which contains multiple paragraphs This is the second paragraph. This is the third paragraph. +## Task List + +- [ ] Task 1 +- [x] Task 2 + ## [Unreleased](https://github.com/olivierlacan/keep-a-changelog/compare/v1.0.0...HEAD) **This Text is Bold** diff --git a/tests/stubs/kitchen-sink.md b/tests/stubs/kitchen-sink.md index 51a41d6..5b312fc 100644 --- a/tests/stubs/kitchen-sink.md +++ b/tests/stubs/kitchen-sink.md @@ -3,19 +3,19 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). -## Task List - -- [ ] Task 1 -- [x] Task 2 - ## Curiosities -- This is a list item which is followed by an indented content on the next line +- This is a list item which is followed by an indented content on the next line which is part of the same list item - This is a list item which contains multiple paragraphs This is the second paragraph. This is the third paragraph. +## Task List + +- [ ] Task 1 +- [x] Task 2 + ## [Unreleased](https://github.com/olivierlacan/keep-a-changelog/compare/v1.0.0...HEAD) **This Text is Bold** From e4ae1338b924ccbd3ea5f36ca403a408712e3bec Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sun, 30 Jul 2023 10:33:58 +0200 Subject: [PATCH 07/10] Replace line breaks in ListItem content with custom string --- src/Renderer/Block/ListItemRenderer.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Renderer/Block/ListItemRenderer.php b/src/Renderer/Block/ListItemRenderer.php index 783d50e..2bcadd1 100644 --- a/src/Renderer/Block/ListItemRenderer.php +++ b/src/Renderer/Block/ListItemRenderer.php @@ -12,6 +12,8 @@ final class ListItemRenderer implements \League\CommonMark\Renderer\NodeRendererInterface { + public const INLINE_LINE_BREAK = '_COMMONMARK_MARKDOWN_RENDERER_LINE_BREAK_'; + /** * @param ListItem $node * @@ -25,11 +27,13 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer): s $contents = $childRenderer->renderNodes($node->children()); - /** + // If the ListItem contains a line break, replace the line break with a custom string. + // The custom line break string is being replaced with a _native_ line break again, when + // being rendered in a ListBlock. + // This workaround is required to support multi-line list items. if (str_contains($contents, "\n")) { - $contents = str_replace("\n", " ", $contents); + $contents = str_replace("\n", self::INLINE_LINE_BREAK, $contents); } - */ if (str_starts_with($contents, '<') && ! $this->startsTaskListItem($node)) { $contents = "\n" . $contents; From 2aafd81a398275f2d4093deb5dcd7089e74c6026 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sun, 30 Jul 2023 10:37:14 +0200 Subject: [PATCH 08/10] Replace custom line breaks in ListBlockRenderer --- src/Renderer/Block/ListBlockRenderer.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Renderer/Block/ListBlockRenderer.php b/src/Renderer/Block/ListBlockRenderer.php index 89ca475..1ede272 100644 --- a/src/Renderer/Block/ListBlockRenderer.php +++ b/src/Renderer/Block/ListBlockRenderer.php @@ -26,6 +26,8 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer): s $content = $childRenderer->renderNodes($node->children()); $content = explode("\n", $content); + $content = array_map(fn ($item) => $this->replaceInternalLineBreakCharacter($item), $content); + if ($listData->type === ListBlock::TYPE_BULLET) { $content = array_map(fn ($item) => "- {$item}", $content); } @@ -42,4 +44,16 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer): s return implode("\n", $content) . "\n"; } + + /** + * Replace custom line break character with _native_ line breaks. + * Whitespace is added so that other Markdown clients correctly + * render the list and its line breaks. + * @param string $content + * @return string + */ + private function replaceInternalLineBreakCharacter(string $content): string + { + return str_replace(ListItemRenderer::INLINE_LINE_BREAK, " \n ", $content); + } } From 89786c437ae71ebed10397005f7bf0ae3cfbdc13 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sun, 30 Jul 2023 10:38:19 +0200 Subject: [PATCH 09/10] Update Kitchen Sink File --- tests/stubs/kitchen-sink-expected.md | 3 +++ tests/stubs/kitchen-sink.md | 3 +++ 2 files changed, 6 insertions(+) diff --git a/tests/stubs/kitchen-sink-expected.md b/tests/stubs/kitchen-sink-expected.md index 5b312fc..68ab37b 100644 --- a/tests/stubs/kitchen-sink-expected.md +++ b/tests/stubs/kitchen-sink-expected.md @@ -10,6 +10,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - This is a list item which contains multiple paragraphs This is the second paragraph. This is the third paragraph. +- This is a list item with multiple paragraphs, but without trailing whitespace in the original document at the end + This is the second paragraph. + This is the third paragraph. ## Task List diff --git a/tests/stubs/kitchen-sink.md b/tests/stubs/kitchen-sink.md index 5b312fc..cb6bb8e 100644 --- a/tests/stubs/kitchen-sink.md +++ b/tests/stubs/kitchen-sink.md @@ -10,6 +10,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - This is a list item which contains multiple paragraphs This is the second paragraph. This is the third paragraph. +- This is a list item with multiple paragraphs, but without trailing whitespace in the original document at the end + This is the second paragraph. + This is the third paragraph. ## Task List From e8d423a4c45fce95bd9dcd2e1ae0e7068535d851 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Tue, 1 Aug 2023 09:01:52 +0200 Subject: [PATCH 10/10] WIP --- tests/Renderer/MarkdownRendererTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Renderer/MarkdownRendererTest.php b/tests/Renderer/MarkdownRendererTest.php index e54a44e..d905698 100644 --- a/tests/Renderer/MarkdownRendererTest.php +++ b/tests/Renderer/MarkdownRendererTest.php @@ -59,8 +59,9 @@ public function it_parses_kitchen_sink_and_parsing_the_result_again_returns_the_ $document = $this->parser->parse($contentKitchenSink); $result = $this->renderer->renderDocument($document)->getContent(); - // $this->assertEquals($contentKitchenSinkExpected, $result); + $this->assertEquals($contentKitchenSinkExpected, $result); + // Take the result and parse it again $document = $this->parser->parse($result); $result = $this->renderer->renderDocument($document)->getContent(); $this->assertEquals($contentKitchenSinkExpected, $result);