Skip to content

Commit cf54de7

Browse files
committed
fix(commands): add support for all ordered list markers in matchLeadingBlockCharacters
1 parent d3e9aa0 commit cf54de7

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/commonmark/commands.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,16 @@ function setBlockType(
192192
/**
193193
* Returns any block formatting characters (plus trailing space) at the very start of the passed text
194194
* @param text The text to check for leading block characters
195+
* @internal
195196
*/
196197
export function matchLeadingBlockCharacters(text: string) {
197198
// TODO this might be too aggressive... remove based on a whitelist instead?
198-
// Match ordered lists prefixes
199-
let match = /^(\d+)\.\s/.exec(text)?.[0];
199+
// Match ordered list markers; see https://spec.commonmark.org/0.30/#ordered-list-marker
200+
let match = /^(\d+)(?:\.|\))\s/.exec(text)?.[0];
200201

201202
// If text is not an ordered list block, check for other block types
202203
if (!match) {
203-
// TODO HACK assumes all non-orderedd list block types are non-letter characters followed by a single space
204+
// TODO HACK assumes all non-ordered list block types are non-letter characters followed by a single space
204205
match = /^[^a-zA-Z0-9]+\s{1}(?=[a-zA-Z0-9_*[!]|$)+/.exec(text)?.[0];
205206
}
206207

test/commonmark/commands.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,17 +530,23 @@ some text`;
530530

531531
expect(command).toBe("");
532532
});
533+
533534
it("return ordered list leading characters", () => {
534-
const command =
535-
commands.matchLeadingBlockCharacters("23. -ol item");
535+
let command = commands.matchLeadingBlockCharacters("23. -ol item");
536536

537537
expect(command).toBe("23. ");
538+
539+
command = commands.matchLeadingBlockCharacters("23) -ol item");
540+
541+
expect(command).toBe("23) ");
538542
});
543+
539544
it("return unordered list leading characters", () => {
540545
const command = commands.matchLeadingBlockCharacters("- 1 ul item");
541546

542547
expect(command).toBe("- ");
543548
});
549+
544550
it("return heading leading characters", () => {
545551
const command =
546552
commands.matchLeadingBlockCharacters("## Heading level 2");

0 commit comments

Comments
 (0)