Skip to content

Commit

Permalink
[BUGFIX] Treat terms with textroles as definition list
Browse files Browse the repository at this point in the history
if they are no field list
  • Loading branch information
linawolf committed Dec 18, 2023
1 parent 4c6eb16 commit b3b14a4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ private function isDefinitionTerm(string|null $currentLine, string|null $nextLin
return false;
}

// This a field list
if (str_starts_with(trim($currentLine), ':')) {
if (FieldListRule::isFieldLine($currentLine)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ public function __construct(private readonly RuleContainer $productions, private

public function applies(BlockContext $blockContext): bool
{
return $this->isFieldLine($blockContext->getDocumentIterator()->current());
return self::isFieldLine($blockContext->getDocumentIterator()->current());
}

public function apply(BlockContext $blockContext, CompoundNode|null $on = null): Node|null
{
$iterator = $blockContext->getDocumentIterator();
$fieldListItemNodes = [];
while ($iterator->valid() && $this->isFieldLine($iterator->current())) {
while ($iterator->valid() && self::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)) {
if (!LinesIterator::isEmptyLine($peek) && !self::isFieldLine($peek)) {
break;
}

Expand Down Expand Up @@ -133,7 +133,7 @@ private function createDefinition(
$buffer = new Buffer();
$documentIterator = $blockContext->getDocumentIterator();
$nextLine = $documentIterator->getNextLine();
if ($nextLine !== null && !$this->isFieldLine($nextLine)) {
if ($nextLine !== null && !self::isFieldLine($nextLine)) {
$indenting = mb_strlen($nextLine) - mb_strlen(trim($nextLine));
if ($indenting > 0) {
$buffer->push(mb_substr($documentIterator->getNextLine() ?? '', $indenting));
Expand Down Expand Up @@ -181,7 +181,7 @@ private function createDefinition(
}
}

private function isFieldLine(string|null $currentLine): bool
public static function isFieldLine(string|null $currentLine): bool
{
if ($currentLine === null) {
return false;
Expand Down
18 changes: 18 additions & 0 deletions tests/Integration/tests/lists/definition-lists/expected/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!-- content start -->
<div class="section" id="definition-list-with-textrole-in-term">
<h1>Definition list with textrole in term</h1>

<dl>
<dt><code>One definition</code></dt>

<dd><p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam</p><p>Nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.</p></dd> <dt><code>Another definition</code></dt>

<dd><div class="admonition note">
<p>sed diam voluptua. At vero eos et accusam et justo duo dolores
et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est.</p>
</div>
<p>Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur.</p></dd> </dl>

</div>

<!-- content end -->
15 changes: 15 additions & 0 deletions tests/Integration/tests/lists/definition-lists/input/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
=====================================
Definition list with textrole in term
=====================================

:code:`One definition`
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam

Nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.

:code:`Another definition`
.. note::
sed diam voluptua. At vero eos et accusam et justo duo dolores
et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est.

Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur.

0 comments on commit b3b14a4

Please sign in to comment.