From 66dd4eab36a492692e19b193783ca680867d4c59 Mon Sep 17 00:00:00 2001 From: Iulia B Date: Fri, 24 Nov 2023 14:04:07 +0000 Subject: [PATCH 1/4] identify multiple spaces in tasklist items --- src/drafts/MarkdownEditor/_useListEditing.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/drafts/MarkdownEditor/_useListEditing.ts b/src/drafts/MarkdownEditor/_useListEditing.ts index ccebce8b5b1..0f2c15d99b9 100644 --- a/src/drafts/MarkdownEditor/_useListEditing.ts +++ b/src/drafts/MarkdownEditor/_useListEditing.ts @@ -29,7 +29,7 @@ const calculateNextListItemStarter = ({leadingWhitespace = '', delimeter, taskBo * 3. Task box (optional) * 4. Everything following */ -export const listItemRegex = /^(\s*)([*-]|(\d+)\.)\s(?:(\[[\sx]\])\s)?(.*)/i +export const listItemRegex = /^(\s*)([*-]|(\d+)\.)(\s{1,2})(?:(\[[\sx]\])\s)?(.*)/i export type ListItem = { leadingWhitespace: string @@ -45,7 +45,7 @@ const isNumericListItem = (item: ListItem | null): item is NumericListItem => ty export const parseListItem = (line: string): ListItem | null => { const result = listItemRegex.exec(line) if (!result) return null - const [, leadingWhitespace = '', fullDelimeter, itemNumberStr = '', taskBox = null, text] = result + const [, leadingWhitespace = '', fullDelimeter, itemNumberStr = '', , taskBox = null, text] = result const itemNumber = Number.parseInt(itemNumberStr, 10) const delimeter = Number.isNaN(itemNumber) ? (fullDelimeter as '*' | '-') : itemNumber From ad9c47fc25f14fd1c5456de51560c7766b883512 Mon Sep 17 00:00:00 2001 From: Iulia B Date: Tue, 28 Nov 2023 17:12:03 +0000 Subject: [PATCH 2/4] parity for whitespace support with classic experience --- src/drafts/MarkdownEditor/_useListEditing.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/drafts/MarkdownEditor/_useListEditing.ts b/src/drafts/MarkdownEditor/_useListEditing.ts index 0f2c15d99b9..e48691ec504 100644 --- a/src/drafts/MarkdownEditor/_useListEditing.ts +++ b/src/drafts/MarkdownEditor/_useListEditing.ts @@ -29,10 +29,11 @@ const calculateNextListItemStarter = ({leadingWhitespace = '', delimeter, taskBo * 3. Task box (optional) * 4. Everything following */ -export const listItemRegex = /^(\s*)([*-]|(\d+)\.)(\s{1,2})(?:(\[[\sx]\])\s)?(.*)/i +export const listItemRegex = /^(\s*)([*-]|(\d+)\.)(\s{1,4})(?:(\[[\sx]\])\s)?(.*)/i export type ListItem = { leadingWhitespace: string + middleWhitespace: string text: string delimeter: '-' | '*' | number taskBox: '[ ]' | '[x]' | null @@ -45,7 +46,7 @@ const isNumericListItem = (item: ListItem | null): item is NumericListItem => ty export const parseListItem = (line: string): ListItem | null => { const result = listItemRegex.exec(line) if (!result) return null - const [, leadingWhitespace = '', fullDelimeter, itemNumberStr = '', , taskBox = null, text] = result + const [, leadingWhitespace = '', fullDelimeter, itemNumberStr = '', middleWhitespace, taskBox = null, text] = result const itemNumber = Number.parseInt(itemNumberStr, 10) const delimeter = Number.isNaN(itemNumber) ? (fullDelimeter as '*' | '-') : itemNumber @@ -53,14 +54,15 @@ export const parseListItem = (line: string): ListItem | null => { leadingWhitespace, text, delimeter, + middleWhitespace, taskBox: taskBox as '[ ]' | '[x]' | null, } } export const listItemToString = (item: ListItem) => `${item.leadingWhitespace}${typeof item.delimeter === 'number' ? `${item.delimeter}.` : item.delimeter}${ - item.taskBox ? ` ${item.taskBox}` : '' - } ${item.text}` + item.middleWhitespace + }${item.taskBox ? ` ${item.taskBox}` : ''} ${item.text}` /** * Provides support for list editing in the Markdown editor. This includes inserting new From 10c0f454e222a969f827b91599fbd5efd96b1858 Mon Sep 17 00:00:00 2001 From: Iulia B Date: Tue, 28 Nov 2023 17:48:44 +0000 Subject: [PATCH 3/4] Remove extra space --- src/drafts/MarkdownEditor/_useListEditing.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drafts/MarkdownEditor/_useListEditing.ts b/src/drafts/MarkdownEditor/_useListEditing.ts index e48691ec504..ac10fd94c2d 100644 --- a/src/drafts/MarkdownEditor/_useListEditing.ts +++ b/src/drafts/MarkdownEditor/_useListEditing.ts @@ -62,7 +62,7 @@ export const parseListItem = (line: string): ListItem | null => { export const listItemToString = (item: ListItem) => `${item.leadingWhitespace}${typeof item.delimeter === 'number' ? `${item.delimeter}.` : item.delimeter}${ item.middleWhitespace - }${item.taskBox ? ` ${item.taskBox}` : ''} ${item.text}` + }${item.taskBox || ''} ${item.text}` /** * Provides support for list editing in the Markdown editor. This includes inserting new From 5d8cc892dc04ed891d0026f925e6dc403c2312b9 Mon Sep 17 00:00:00 2001 From: Josh Black Date: Tue, 28 Nov 2023 12:42:21 -0600 Subject: [PATCH 4/4] chore: add changeset --- .changeset/strong-swans-repeat.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/strong-swans-repeat.md diff --git a/.changeset/strong-swans-repeat.md b/.changeset/strong-swans-repeat.md new file mode 100644 index 00000000000..3ba440e4ccd --- /dev/null +++ b/.changeset/strong-swans-repeat.md @@ -0,0 +1,5 @@ +--- +'@primer/react': patch +--- + +Update MarkdownEditor to correctly identify non-standard formatted tasklist items