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

🏷 Propagate block metatags to code node and output node #407

Merged
merged 10 commits into from
Jun 10, 2023

Conversation

GYHHAHA
Copy link
Contributor

@GYHHAHA GYHHAHA commented Jun 2, 2023

This is the first part of implementation for jupyter meta tags support, as discussed in here.

After merging this, there are at least 4 things on the list:

  • release new myst-cli and myst-spec-ext version
  • change according components in myst-theme
  • create new block component to control the visibility of the whole cell
  • update doc on the executable content section

For this pr, there are still 2 questions, which are mentioned in the comments:

  • can we ensure that there will only have single code node and output node in a block node?
  • will we raise when hide-xx and remove-xx appear at the same time?

Copy link
Collaborator

@rowanc1 rowanc1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, this is looking great! I added a few minor comments about searching through the MDAST and handling a few other cases of the markdown cells, blocks without output (or perhaps code, but that would be weird).

I also think we want to leave tags on the block that we haven't processed here.

packages/myst-cli/src/transforms/code.ts Outdated Show resolved Hide resolved
packages/myst-cli/src/transforms/code.ts Outdated Show resolved Hide resolved
packages/myst-cli/src/transforms/code.ts Outdated Show resolved Hide resolved
packages/myst-spec-ext/src/types.ts Show resolved Hide resolved
packages/myst-cli/src/transforms/code.ts Outdated Show resolved Hide resolved
packages/myst-cli/src/transforms/code.spec.ts Show resolved Hide resolved
* Traverse mdast, propagate block tags to code and output
*/
export function propagateBlockDataToCode(session: ISession, filename: string, mdast: Root) {
const blocks = selectAll('block', mdast) as GenericNode[];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is possible that this might grab too many blocks (e.g. the markdown ones, which aren't going to have the code/output). I think we put a kind or something on the block, not sure where that is at the moment!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is changed, it's reasonable to change the liftCodeMetadataToBlock with the same way. This worth a separate pr to do since two tests will be added and their functionality do not have direct link to the meta tag implementation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good -- let me know when you are a bit further on the feature and I can go in and test against a few other projects!

@rowanc1
Copy link
Collaborator

rowanc1 commented Jun 7, 2023

For will we raise when hide-xx and remove-xx appear at the same time? I think that we could raise a warning, and then go with the most strict -- i.e. remove > hide > show.

@rowanc1
Copy link
Collaborator

rowanc1 commented Jun 8, 2023

For release new myst-cli and myst-spec-ext version task can you add a changeset:

npm run changeset

This will guide you through the process of noting which libraries need to be patched/released!

Co-authored-by: Rowan Cockett <rowanc1@gmail.com>
@rowanc1
Copy link
Collaborator

rowanc1 commented Jun 8, 2023

From a functionality point of view do you think the feature is now complete? Core-review wise it looks solid!
Let me know and I can take it for a test drive. :)

@GYHHAHA
Copy link
Contributor Author

GYHHAHA commented Jun 8, 2023

For mystjs side, it is complete. But as you see from my task list, changes should also be made in myst-to-react which now I'm going to do after I'm able to use this new myst-cli version.

@rowanc1
Copy link
Collaborator

rowanc1 commented Jun 8, 2023

Perfect -- I will try to get to this today!

@GYHHAHA
Copy link
Contributor Author

GYHHAHA commented Jun 9, 2023

Hi @rowanc1, if you are planning to merge this in and do a patch release today, I will have some spare time to finish the rest of tasks in myst-theme at this weekend. Not rushing, just want to know is there any blocker. Thanks 😊

@rowanc1
Copy link
Collaborator

rowanc1 commented Jun 9, 2023

Hi @GYHHAHA I was stuck doing some major code renovations over in #417. I think that will help a lot of things, including the dev experience and downstream packaging. But it will probably mean a few issues with the merge, I will try to deal with them and then get on to testing this shortly!!

@GYHHAHA
Copy link
Contributor Author

GYHHAHA commented Jun 9, 2023

Sure! I think this will be great. Take your time!

@rowanc1
Copy link
Collaborator

rowanc1 commented Jun 9, 2023

Didn't quite get to actually testing, I hope I can get to it this eve -- tests are now passing again though! :)

blocks.forEach((block) => {
if (!block.data || !block.data.tags) return;
if (!Array.isArray(block.data.tags)) {
session.log.error(`tags in code-cell directive must be a list of strings`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am tweaking this a bit to pass in the node and file information for better console tracking:

image

@rowanc1
Copy link
Collaborator

rowanc1 commented Jun 10, 2023

This looks great! I am going to merge and release once the tests go green. We should add some docs after we get the frontend working!

Thanks again for your help on this feature, another check on #189. ✅ 🚀

@rowanc1 rowanc1 merged commit 072e338 into jupyter-book:main Jun 10, 2023
@rowanc1 rowanc1 changed the title Propagate block metatags to code node and output node 🏷 Propagate block metatags to code node and output node Jun 10, 2023
@rowanc1
Copy link
Collaborator

rowanc1 commented Jun 10, 2023

This is released as v1.0.2. 🚀 Let me know how the theme work goes or if you need any help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants