Skip to content

Commit 336d3e3

Browse files
committed
Add support for alphabethic lists.
1 parent e3b0725 commit 336d3e3

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

packages/guides-restructured-text/src/RestructuredText/Parser/Productions/EnumeratedListRule.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ final class EnumeratedListRule implements Rule
4747
private const ROMAN_NUMBER = '((?:M{0,3})(?:CM|CD|D?C{0,3})(?:XC|XL|L?X{0,3})(?:IX|IV|V?I{0,3}))(?<!^)';
4848
private const NUMBER = '(\d+|#)';
4949

50-
private const ALPHABETIC = '[a-z]';
50+
private const ALPHABETIC = '([a-z])';
5151

5252
private const LIST_MARKER = '(^%s([\.)])(?:\s+|$)|^[(]%s[)](?:\s+|$))';
5353

@@ -144,8 +144,8 @@ private function getItemConfig(string $line): array
144144
}
145145

146146
return [
147-
'marker' => trim($m[1]),
148-
'marker_type' => $this->getMarkerType($m[1]),
147+
'marker' => trim($m[0]),
148+
'marker_type' => $this->getMarkerType($m[0]),
149149
'indenting' => $m[0] === $line ? 1 : mb_strlen($m[0]),
150150
];
151151
}
@@ -161,7 +161,7 @@ private function isListItemStart(string|null $line, string|null $listMarker = nu
161161
return false;
162162
}
163163

164-
$normalizedMarker = $this->getMarkerType($m[1]);
164+
$normalizedMarker = $this->getMarkerType($m[0]);
165165

166166
if ($normalizedMarker === 'unknown') {
167167
return false;
@@ -222,6 +222,10 @@ private function getMarkerType(string $marker): string
222222
return 'roman' . $this->markerSuffix($marker);
223223
}
224224

225+
if (preg_match('/' . sprintf(self::LIST_MARKER, self::ALPHABETIC, self::ALPHABETIC) . '/', $marker)) {
226+
return 'alphabetic' . $this->markerSuffix($marker);
227+
}
228+
225229
return 'unknown';
226230
}
227231

File renamed without changes.

tests/Functional/tests/enumerated/enumerated.html renamed to tests/Functional/tests/list-enumerated/list-enumerated.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,15 @@
2121
<li value="1">First item</li>
2222
<li value="2">Second item</li>
2323
</ol>
24+
<p>This is an enumerated list using letters:</p>
25+
<ol start="a" type="a">
26+
<li value="a">First</li>
27+
<li value="b">Second</li>
28+
<li value="c">Third</li>
29+
</ol>
30+
<p>This is an roman list using letters:</p>
31+
<ol start="I" type="i">
32+
<li value="I">First</li>
33+
<li value="II">Second</li>
34+
<li value="III">Third</li>
35+
</ol>

tests/Functional/tests/enumerated/enumerated.rst renamed to tests/Functional/tests/list-enumerated/list-enumerated.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,15 @@ Using right-parenthesis:
2020

2121
1) First item
2222
2) Second item
23+
24+
This is an enumerated list using letters:
25+
26+
a. First
27+
b. Second
28+
c. Third
29+
30+
This is an roman list using letters:
31+
32+
I. First
33+
II. Second
34+
III. Third

0 commit comments

Comments
 (0)