Skip to content

Commit

Permalink
Merge pull request #154 from wouterj/sf-108
Browse files Browse the repository at this point in the history
Fix parsing definition list term
  • Loading branch information
greg0ire authored Jul 9, 2021
2 parents 5402402 + ade7d1d commit 55253fc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
8 changes: 3 additions & 5 deletions lib/Parser/LineDataParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Doctrine\RST\Parser;

use function array_map;
use function array_shift;
use function count;
use function explode;
use function ltrim;
Expand Down Expand Up @@ -210,11 +211,8 @@ public function parseDefinitionList(array $lines): DefinitionList
$definitionList[] = $createDefinitionTerm($definitionListTerm);
}

$parts = explode(':', trim($line));

$term = $parts[0];
unset($parts[0]);

$parts = explode(' : ', trim($line));
$term = array_shift($parts);
$classifiers = array_map(function (string $classifier): SpanNode {
return $this->parser->createSpanNode($classifier);
}, array_map('trim', $parts));
Expand Down
2 changes: 0 additions & 2 deletions lib/Templates/default/html/definition-list.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{% apply spaceless %}
<dl{% if definitionListNode.classes %} class="{{ definitionListNode.classesString }}"{% endif %}>
{% for definitionListTerm in definitionList.terms %}
{% if definitionListTerm.classifiers is empty %}
Expand All @@ -21,4 +20,3 @@
</dd>
{% endfor %}
</dl>
{% endapply %}
12 changes: 7 additions & 5 deletions tests/Functional/tests/definition-list/definition-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@ <h1>
<p>Definition 2</p>
<p class="last">Definition 3</p>
</dd>
<dt> term 3 <span class="classifier-delimiter">:</span><span class="classifier">classifier</span></dt>
<dt> term 3 <span class="classifier-delimiter">:</span> <span class="classifier">classifier</span> </dt>
<dd> Definition 1 </dd>
<dt> term 4 <span class="classifier-delimiter">:</span><span class="classifier">classifier one</span><span class="classifier-delimiter">:</span><span class="classifier">classifier two</span></dt>
<dt> term 4 <span class="classifier-delimiter">:</span> <span class="classifier">classifier one</span> <span class="classifier-delimiter">:</span> <span class="classifier">classifier two</span> </dt>
<dd> Definition 1 </dd>
<dt> term with &amp; <span class="classifier-delimiter">:</span><span class="classifier">classifier with &amp;</span></dt>
<dt> term with &amp; <span class="classifier-delimiter">:</span> <span class="classifier">classifier with &amp;</span> </dt>
<dd> Definition 1 with &amp; </dd>
<dt> term with &amp; <span class="classifier-delimiter">:</span><span class="classifier">classifier with &amp;</span><span class="classifier-delimiter">:</span><span class="classifier">classifier with &amp;</span></dt>
<dt> term with &amp; <span class="classifier-delimiter">:</span> <span class="classifier">classifier with &amp;</span> <span class="classifier-delimiter">:</span> <span class="classifier">classifier with &amp;</span> </dt>
<dd>
<p class="first">Definition 1 with &amp;</p>
<p class="last">Definition 2 with &amp;</p>
</dd>
<dt>
<code>term 5</code><span class="classifier-delimiter">:</span>
<code>term 5</code> <span class="classifier-delimiter">:</span>
<span class="classifier"><code>classifier</code></span>
</dt>
<dd> Definition 1 </dd>
<dt><strong>Complex:</strong> <code>int</code></dt>
<dd> Colon must be surrounded by spaces to be a term identifier </dd>
<dt>multi-line definition term</dt>
<dd>
<p class="first">Definition 1 line 1
Expand Down
3 changes: 3 additions & 0 deletions tests/Functional/tests/definition-list/definition-list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ term with & : classifier with & : classifier with &
``term 5`` : ``classifier``
Definition 1

**Complex:** ``int``
Colon must be surrounded by spaces to be a term identifier

multi-line definition term
Definition 1 line 1
Definition 1 line 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ <h1>
<blockquote>
<hr />
<dl>
<dt> Received <span class="classifier-delimiter">:</span><span class="classifier">from x.y.test</span></dt>
<dt>Received: from x.y.test</dt>
<dd> by example.net
via TCP
with ESMTP
Expand Down

0 comments on commit 55253fc

Please # to comment.