From e7e9766bd77ae0afa0fe4e1bb960c0fa92bfe618 Mon Sep 17 00:00:00 2001 From: "lina.wolf" Date: Sun, 26 Nov 2023 10:57:24 +0100 Subject: [PATCH] [BUGFIX] Allow empty lines between field list items They are also allowed in Sphinx and we frequently have them in TYPO3. --- .../Parser/Productions/FieldListRule.php | 14 +++++++- .../expected/index.html | 35 +++++++++++++++++++ .../field-list-empty-lines/input/index.rst | 21 +++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 tests/Integration/tests/lists/field-list-empty-lines/expected/index.html create mode 100644 tests/Integration/tests/lists/field-list-empty-lines/input/index.rst diff --git a/packages/guides-restructured-text/src/RestructuredText/Parser/Productions/FieldListRule.php b/packages/guides-restructured-text/src/RestructuredText/Parser/Productions/FieldListRule.php index 8039a8832..f53122164 100644 --- a/packages/guides-restructured-text/src/RestructuredText/Parser/Productions/FieldListRule.php +++ b/packages/guides-restructured-text/src/RestructuredText/Parser/Productions/FieldListRule.php @@ -55,6 +55,14 @@ public function apply(BlockContext $blockContext, CompoundNode|null $on = null): while ($iterator->valid() && $this->isFieldLine($iterator->current())) { $fieldListItemNodes[] = $this->createListItem($blockContext); $iterator->next(); + while ($iterator->valid() && LinesIterator::isEmptyLine($iterator->current())) { + $peek = $iterator->peek(); + if (!LinesIterator::isEmptyLine($peek) && !$this->isFieldLine($peek)) { + break; + } + + $iterator->next(); + } } if ($on instanceof DocumentNode && !$on->isTitleFound()) { @@ -173,8 +181,12 @@ private function createDefinition( } } - private function isFieldLine(string $currentLine): bool + private function isFieldLine(string|null $currentLine): bool { + if ($currentLine === null) { + return false; + } + if (LinesIterator::isEmptyLine($currentLine)) { return false; } diff --git a/tests/Integration/tests/lists/field-list-empty-lines/expected/index.html b/tests/Integration/tests/lists/field-list-empty-lines/expected/index.html new file mode 100644 index 000000000..12a7c1f81 --- /dev/null +++ b/tests/Integration/tests/lists/field-list-empty-lines/expected/index.html @@ -0,0 +1,35 @@ + +
+

Test

+ + + + + + + + + + + + + + + + + + + + + + +
Version +
Language +

en

Author +

Contributors

Rendered +

Sun, 01 Jan 2023 12:00:00 +0000

+ +

Something else.

+
+ + diff --git a/tests/Integration/tests/lists/field-list-empty-lines/input/index.rst b/tests/Integration/tests/lists/field-list-empty-lines/input/index.rst new file mode 100644 index 000000000..3a01fc598 --- /dev/null +++ b/tests/Integration/tests/lists/field-list-empty-lines/input/index.rst @@ -0,0 +1,21 @@ +==== +Test +==== + +:Version: + |release| + +:Language: + en + + +:Author: + Contributors + + + + +:Rendered: + |today| + +Something else. \ No newline at end of file