Skip to content
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

Merged
merged 2 commits into from
Mar 22, 2023
Merged

✅ Editable task lists #121

merged 2 commits into from
Mar 22, 2023

Conversation

rowanc1
Copy link
Member

@rowanc1 rowanc1 commented Mar 22, 2023

See #63

tasklists-in-jupyterlab

tasklists

fancy-tasklists

@github-actions
Copy link
Contributor

Binder 👈 Launch a Binder on branch executablebooks/jupyterlab-myst/feat/tasklists

@rowanc1 rowanc1 requested a review from agoose77 March 22, 2023 05:49
@rowanc1 rowanc1 added the enhancement New feature or request label Mar 22, 2023
Comment on lines +20 to +42
<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>
Copy link
Collaborator

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]\])/,
Copy link
Collaborator

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.

@agoose77 agoose77 merged commit dbe5fd2 into main Mar 22, 2023
@agoose77 agoose77 deleted the feat/tasklists branch March 22, 2023 09:13
@agoose77 agoose77 mentioned this pull request Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants