From 7e47aab71ebb240b19dca0ce70195b5a841849c1 Mon Sep 17 00:00:00 2001 From: Arnout Boks Date: Tue, 25 Oct 2022 15:15:58 +0200 Subject: [PATCH] Fix incorrect preference for multi-letter alpha over Roman --- README.md | 3 ++- src/ListParser.php | 4 +-- test/MultiLetterIntegrationTest.php | 40 +++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2425f09..0511656 100644 --- a/README.md +++ b/README.md @@ -168,7 +168,8 @@ Supported configuration options: ``` Multi-letter alphabetic numerals can consist of at most 3 characters, which should be enough for a - typical list. + typical list. When a list starts with a numeral that can be both Roman or multi-letter alphabetic, + like "II", it is considered to be Roman. Versioning ---------- diff --git a/src/ListParser.php b/src/ListParser.php index 06b4942..330aa1d 100644 --- a/src/ListParser.php +++ b/src/ListParser.php @@ -103,7 +103,7 @@ public function parse(ContextInterface $context, Cursor $cursor): bool $isValidRoman = false; } $isValidAlpha = strlen($matches[1]) === 1 || $this->config->get('allow_multi_letter', false); - $preferRomanOverAlpha = $withinRomanList || (!$withinAlphaList && $matches[1] === 'I'); + $preferRomanOverAlpha = $withinRomanList || (!$withinAlphaList && ($matches[1] === 'I' || strlen($matches[1]) > 1)); if ($isValidRoman && (!$isValidAlpha || $preferRomanOverAlpha)) { $data->start = $parsedRomanNumber; @@ -124,7 +124,7 @@ public function parse(ContextInterface $context, Cursor $cursor): bool $isValidRoman = false; } $isValidAlpha = strlen($matches[1]) === 1 || $this->config->get('allow_multi_letter', false); - $preferRomanOverAlpha = $withinRomanList || (!$withinAlphaList && $matches[1] === 'i'); + $preferRomanOverAlpha = $withinRomanList || (!$withinAlphaList && ($matches[1] === 'i' || strlen($matches[1]) > 1)); if ($isValidRoman && (!$isValidAlpha || $preferRomanOverAlpha)) { $data->start = $parsedRomanNumber; diff --git a/test/MultiLetterIntegrationTest.php b/test/MultiLetterIntegrationTest.php index 730ea73..ad00f8f 100644 --- a/test/MultiLetterIntegrationTest.php +++ b/test/MultiLetterIntegrationTest.php @@ -108,6 +108,46 @@ public function testDoesNotSupportMixingUppercaseAndLowercaseLetters(): void

Aa) foo Ab) bar Ac) baz

+HTML; + + $this->assertMarkdownIsConvertedTo($expectedHtml, $markdown, [ + 'allow_multi_letter' => true, + ]); + } + + public function testPrefersRomanNumeralsOverMultiLetterAlphabeticNumerals(): void + { + $markdown = << +
  • foo
  • +
  • bar
  • +
  • baz
  • + +HTML; + + $this->assertMarkdownIsConvertedTo($expectedHtml, $markdown, [ + 'allow_multi_letter' => true, + ]); + } + + public function testPrefersMultiLetterAlphabeticNumeralsOverRomanNumeralsWhenAlreadyInAnAlphabeticList(): void + { + $markdown = << +
  • foo
  • +
  • bar
  • +
  • baz
  • + HTML; $this->assertMarkdownIsConvertedTo($expectedHtml, $markdown, [