Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Treat terms with textroles as definition list #765

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use function ltrim;
use function mb_strlen;
use function mb_substr;
use function preg_match;
use function str_starts_with;
use function trim;

Expand All @@ -44,8 +45,10 @@ final class DefinitionListRule implements Rule
{
public const PRIORITY = 30;

public function __construct(private readonly InlineMarkupRule $inlineMarkupRule, private readonly RuleContainer $bodyElements)
{
public function __construct(
private readonly InlineMarkupRule $inlineMarkupRule,
private readonly RuleContainer $bodyElements,
) {
}

public function applies(BlockContext $blockContext): bool
Expand Down Expand Up @@ -156,8 +159,8 @@ private function isDefinitionTerm(string|null $currentLine, string|null $nextLin
return false;
}

// This a field list
if (str_starts_with(trim($currentLine), ':')) {
// This is a field list
if (preg_match('/^:([^:]+):( (.*)|)$/mUsi', $currentLine) > 0) {
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
private static function isFieldLine(string|null $currentLine): bool
{
if ($currentLine === null) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.17.0@c620f6e80d0abfca532b00bda366062aaedf6e5d">
<files psalm-version="5.18.0@b113f3ed0259fd6e212d87c3df80eec95a6abf19">
<file src="packages/guides-cli/src/Config/Configuration.php">
<UndefinedMethod>
<code>ignoreExtraKeys</code>
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.