-
Notifications
You must be signed in to change notification settings - Fork 18
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
✅ Editable task lists #121
Conversation
<li className="task-list-item"> | ||
<input | ||
type="checkbox" | ||
disabled={!cell} | ||
className="task-list-item-checkbox" | ||
checked={local} | ||
onClick={() => { | ||
// Bail if no line number was found | ||
if (!cell || line == null) return; | ||
const text = cell.model.value.text; | ||
// This is a pretty cautious replacement for the identified line | ||
const lines = text.split('\n'); | ||
lines[line] = lines[line].replace( | ||
/^(\s*(?:-|\*)\s*)(\[[\s|x]\])/, | ||
local ? '$1[ ]' : '$1[x]' | ||
); | ||
setLocal(!local); | ||
// Update the Jupyter cell markdown value | ||
cell.model.value.text = lines.join('\n'); | ||
}} | ||
/> | ||
{children} | ||
</li> |
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.
In the long run, it would be ideal if we can modify the mdast and round trip it to text. Do you think that's feasible down the line? IIRC we do maintain sufficient information in the AST to do such a thing.
For this PR, this is clearly the "best" approach, though; we're short on time and can make iterative jumps.
// This is a pretty cautious replacement for the identified line | ||
const lines = text.split('\n'); | ||
lines[line] = lines[line].replace( | ||
/^(\s*(?:-|\*)\s*)(\[[\s|x]\])/, |
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.
This regex is more permissive than https://myst-tools.org/sandbox's parser. However, I think that's fine; I don't think someone can write MyST that produces a list element after markup that matches this regex and doesn't break the remaining parse. Not super confident, though I don't think it matters; this is a WIP.
See #63