Skip to content

Commit

Permalink
Mobile,Desktop: Fixes #11135: Fix incorrect numbered list regex
Browse files Browse the repository at this point in the history
  • Loading branch information
personalizedrefrigerator committed Sep 27, 2024
1 parent eda2c69 commit 2ad99c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,19 @@ describe('markdownCommands.toggleList', () => {
);
expect(editor.state.selection.main.from).toBe(preSubListText.length);
});

it('should not treat a list of IP addresses as a numbered list', async () => {
const initialDocText = '192.168.1.1. This\n127.0.0.1. is\n0.0.0.0. a list';

const editor = await createTestEditor(
initialDocText,
EditorSelection.range(0, initialDocText.length),
[],
);

toggleList(ListType.UnorderedList)(editor);
expect(editor.state.doc.toString()).toBe(
'- 192.168.1.1. This\n- 127.0.0.1. is\n- 0.0.0.0. a list',
);
});
});
6 changes: 3 additions & 3 deletions packages/editor/CodeMirror/markdown/markdownCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ export const toggleList = (listType: ListType): Command => {
// RegExps for different list types. The regular expressions MUST
// be mutually exclusive.
// `(?!\[[ xX]+\])` means "not followed by [x] or [ ]".
const bulletedRegex = /^\s*([-*])\s(?!\[[ xX]+\])/;
const checklistRegex = /^\s*[-*]\s\[[ xX]+\]\s?/;
const numberedRegex = /^\s*\d+\.\s?/;
const bulletedRegex = /^\s*([-*])\s(?!\[[ xX]+\]\s)/;
const checklistRegex = /^\s*[-*]\s\[[ xX]+\]\s/;
const numberedRegex = /^\s*\d+\.\s/;

const listRegexes: Record<ListType, RegExp> = {
[ListType.OrderedList]: numberedRegex,
Expand Down

0 comments on commit 2ad99c9

Please sign in to comment.