Skip to content

Commit e59ce7e

Browse files
committed
Fix incorrect preference for multi-letter alpha over Roman
1 parent 0ab9b89 commit e59ce7e

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ Supported configuration options:
165165
</ol>
166166
```
167167
Multi-letter alphabetic numerals can consist of at most 3 characters, which should be enough for a
168-
typical list.
168+
typical list. When a list starts with a numeral that can be both Roman or multi-letter alphabetic,
169+
like "II", it is considered to be Roman.
169170

170171
Versioning
171172
----------

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ function analyseMarker(state: StateBlock, startLine: number, endLine: number, pr
149149
};
150150
} else if (isCharCodeLowercaseAlpha(charCode)) {
151151
const isValidAlpha = bulletChar.length === 1 || options.allowMultiLetter === true;
152-
const preferRoman = ((previousMarker !== null && previousMarker.isRoman === true) || ((previousMarker === null || previousMarker.isAlpha === false) && bulletChar === "i"));
152+
const preferRoman = ((previousMarker !== null && previousMarker.isRoman === true) || ((previousMarker === null || previousMarker.isAlpha === false) && (bulletChar === "i" || bulletChar.length > 1)));
153153
const { parsedRomanNumber, isValidRoman } = analyzeRoman(bulletChar);
154154

155155
if (isValidRoman === true && (isValidAlpha === false || preferRoman === true)) {
@@ -174,7 +174,7 @@ function analyseMarker(state: StateBlock, startLine: number, endLine: number, pr
174174
return null;
175175
} else if (isCharCodeUppercaseAlpha(charCode)) {
176176
const isValidAlpha = bulletChar.length === 1 || options.allowMultiLetter === true;
177-
const preferRoman = ((previousMarker !== null && previousMarker.isRoman === true) || ((previousMarker === null || previousMarker.isAlpha === false) && bulletChar === "I"));
177+
const preferRoman = ((previousMarker !== null && previousMarker.isRoman === true) || ((previousMarker === null || previousMarker.isAlpha === false) && (bulletChar === "I" || bulletChar.length > 1)));
178178
const { parsedRomanNumber, isValidRoman } = analyzeRoman(bulletChar);
179179

180180
if (isValidRoman === true && (isValidAlpha === false || preferRoman === true)) {

test/index.ts

+36
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,42 @@ Ac) baz
784784
<p>Aa) foo
785785
Ab) bar
786786
Ac) baz</p>
787+
`;
788+
await assertHTML(expectedHtml, markdown, {
789+
allowMultiLetter: true,
790+
});
791+
});
792+
793+
it("prefers roman numerals over multi-letter alphabetic numerals", async () => {
794+
const markdown = `
795+
II) foo
796+
III) bar
797+
IV) baz
798+
`;
799+
const expectedHtml = `
800+
<ol type="I" start="2">
801+
<li>foo</li>
802+
<li>bar</li>
803+
<li>baz</li>
804+
</ol>
805+
`;
806+
await assertHTML(expectedHtml, markdown, {
807+
allowMultiLetter: true,
808+
});
809+
});
810+
811+
it("prefers multi-letter alphabetic numerals over roman numerals when already in an alphabetic list", async () => {
812+
const markdown = `
813+
IH) foo
814+
II) bar
815+
IJ) baz
816+
`;
817+
const expectedHtml = `
818+
<ol type="A" start="242">
819+
<li>foo</li>
820+
<li>bar</li>
821+
<li>baz</li>
822+
</ol>
787823
`;
788824
await assertHTML(expectedHtml, markdown, {
789825
allowMultiLetter: true,

0 commit comments

Comments
 (0)