-
Notifications
You must be signed in to change notification settings - Fork 670
Fix legacy task list position calculation #3491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
ac211f0
b456e32
8e5df65
c2e70df
22cc801
89809a3
26b488f
f5e867b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,17 @@ import {ListItem, listItemToString, parseListItem} from '../MarkdownEditor/_useL | |||||
|
|
||||||
| type TaskListItem = ListItem & {taskBox: '[ ]' | '[x]'} | ||||||
|
|
||||||
| // Make check for code fences more robust per spec: https://github.github.com/gfm/#fenced-code-blocks | ||||||
| const parseCodeFenceBegin = (line: string) => { | ||||||
| const match = line.match(/^ {0,3}(`{3,}|~{3,})[^`]*$/) | ||||||
| return match ? match[1] : null | ||||||
| } | ||||||
|
|
||||||
| const isCodeFenceEnd = (line: string, fence: string) => { | ||||||
| const match = line.match(new RegExp(`^ {0,3}${fence}${fence[0]}* *$`)) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think the closing fence needs to have exactly the same number of delimiters as the opening fence. For example, this is valid: ```one
````
we are still in block `one` here
```
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically the closing fence needs to have "at least as many" delimiters as the opening fence:
So in the case you mentioned above, the second line would suffice as a closing fence since it has "at least" three backticks (tested in the issue editor on prod and confirmed).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh wow, you are totally right 👍 I definitely misread that |
||||||
| return match !== null | ||||||
|
iansan5653 marked this conversation as resolved.
Outdated
|
||||||
| } | ||||||
|
|
||||||
| const isTaskListItem = (item: ListItem | null): item is TaskListItem => typeof item?.taskBox === 'string' | ||||||
|
|
||||||
| const toggleTaskListItem = (item: TaskListItem): TaskListItem => ({ | ||||||
|
|
@@ -43,9 +54,21 @@ export const useListInteraction = ({ | |||||
| const onToggleItem = useCallback( | ||||||
| (toggledItemIndex: number) => () => { | ||||||
| const lines = markdownRef.current.split('\n') | ||||||
| let currentCodeFence: string | null = null | ||||||
|
|
||||||
| for (let lineIndex = 0, taskIndex = 0; lineIndex < lines.length; lineIndex++) { | ||||||
| const parsedLine = parseListItem(lines[lineIndex]) | ||||||
| const line = lines[lineIndex] | ||||||
|
|
||||||
| if (!currentCodeFence) { | ||||||
| currentCodeFence = parseCodeFenceBegin(line) | ||||||
| } else if (isCodeFenceEnd(line, currentCodeFence)) { | ||||||
| currentCodeFence = null | ||||||
| continue | ||||||
| } | ||||||
|
|
||||||
| if (currentCodeFence) continue | ||||||
|
|
||||||
| const parsedLine = parseListItem(line) | ||||||
|
|
||||||
| if (!isTaskListItem(parsedLine)) continue | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the spec says that an opening fence can be indented an indefinite number of spaces, but the closing fence can only be indented up to 3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec states that both an opening and closing fence can be indented no more than three spaces:
I also tested and confirmed this is the case.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, the spec has an example with more than three, but I think I misread it - it looks like that doesn't actually make a code block. So, all good 👍
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note, maybe we also should filter out lines starting with more than 3 spaces?
Ie, this is not a checklist item, but it's also not in a code block:
This came from this markdown:
- [ ] exampleProbably something to think about for a different PR though