Skip to content

✨ Add text/markdown MIME renderer#102

Merged
agoose77 merged 20 commits into
jupyter-book:mainfrom
agoose77:feat-mime-renderer
May 30, 2023
Merged

✨ Add text/markdown MIME renderer#102
agoose77 merged 20 commits into
jupyter-book:mainfrom
agoose77:feat-mime-renderer

Conversation

@agoose77

@agoose77 agoose77 commented Feb 27, 2023

Copy link
Copy Markdown
Collaborator

Fixes #100 by overwriting the default text/markdown MIME renderer with a MyST enabled renderer.

@github-actions

Copy link
Copy Markdown
Contributor

Binder 👈 Launch a Binder on branch agoose77/jupyterlab-myst/feat-mime-renderer

@agoose77

Copy link
Copy Markdown
Collaborator Author

@rowanc1 deleting the yarn lockfile leads to the build failing. I can't figure out exactly what the error is, hoping you'll know.

@rowanc1 rowanc1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Adding a few thoughts as I look through this!

Comment thread package.json Outdated
Comment thread src/myst.ts
Comment thread src/mime.tsx Outdated
this.resolver = options.resolver;
this.linkHandler = options.linkHandler;
this.node.dataset['mimeType'] = MIME_TYPE;
this.addClass('myst-RenderedMySTMarkdown');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is some css that requires this to be wrapped in a top-level myst, we can change the name of that, but it will need it to be the same as the cell, or added in.

Comment thread src/mime.tsx Outdated
Comment on lines +136 to +143
const { frontmatter: frontmatterRaw } = getFrontmatter(
// This is a bit weird, but if there is a YAML block in the first cell, this is where it will be.
mdast,
{
removeYaml: true,
removeHeading: true
}
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My understanding is that this is for inline markdown? I think that we shouldn't parse the frontmatter unless it is specifically the first cell of a notebook.

Comment thread src/mime.tsx
>
<TabStateProvider>
<ReferencesProvider
references={references}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this intended to share the state with other cells, e.g. can you reference an equation in the notebook with this?

It that is the case, then this needs to be the shared references, which gets a bit tricky (maybe?)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes it does! When I wrote this PR initially, I just wanted to get the majority of the boilerplate on the page. The semantics are probably in need of some work :)

@agoose77 agoose77 changed the title wip: add mime renderer feat: add text/markdown MIME renderer Feb 27, 2023
@agoose77

agoose77 commented Feb 27, 2023

Copy link
Copy Markdown
Collaborator Author

@rowanc1 this now builds, and renders, but it's a bit broken:

  • styles seem a bit borked
  • no scrolling
  • front matter seems duplicated

I just wired everything together (I have no high-level understanding of the details of the AST transform/rendering), so I'm not surprised. Are you happy to take over this PR when you're next free (no rush)?

@tavin

tavin commented May 1, 2023

Copy link
Copy Markdown
Contributor

@agoose77 @rowanc1 I was trying to grok this PR over the weekend... does it need to be rebased off the latest main branch?

Comment thread package.json
Comment thread yarn.lock
@agoose77 agoose77 force-pushed the feat-mime-renderer branch from 0ce22a0 to 8bff032 Compare May 12, 2023 09:17
Comment thread src/mime.tsx
this.resolver = options.resolver;
this.linkHandler = options.linkHandler;
this.node.dataset['mimeType'] = MIME_TYPE;
this.addClass('jp-RenderedMySTMarkdown');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should this be jp-MarkdownOutput? or both?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'm avoiding using the Jupyter tags, as they bring their own assumptions that might not reflect ours. We don't use the jp tags elsewhere, but if we need to, we can! For now, assuming not.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ok, I was comparing with the CSS classes used on the notebook side (that make styles and scrolling work) -- I haven't tried your latest changes yet

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ah, I see! I've fixed the scrolling (setting overflow rules, although it's currently a private variable - we should use our own), and the styles look correct to me, now.

@agoose77 agoose77 changed the title feat: add text/markdown MIME renderer ✨ Add text/markdown MIME renderer May 12, 2023
@agoose77 agoose77 added the enhancement New feature or request label May 15, 2023
@tavin

tavin commented May 15, 2023

Copy link
Copy Markdown
Contributor

@rowanc1 deleting the yarn lockfile leads to the build failing. I can't figure out exactly what the error is, hoping you'll know.

@agoose77 I just came across this old remark of yours -- I think the answer is indeed pinning the @jupyterlab deps, either using resolutions or else by eschewing the caret i.e. 3.5.1 instead of ^3.5.1 ... 3.4.7 will downgrade the yarn lockfile at this point, but maybe that's okay.

@agoose77

agoose77 commented May 15, 2023

Copy link
Copy Markdown
Collaborator Author

I think the answer is indeed pinning the @jupyterlab deps, either using resolutions or else by eschewing the caret i.e. 3.5.1 instead of ^3.5.1

We want to support all versions of JupyterLab greater than our lower bound. Therefore, I think we don't even want to pin these deps during development, as it means we'll catch these kinds of failures before someone installs the package in whichever JupyterLab is misbehaving.

Although we could probably go lower than 3.4.7, that's the minimum version that our PyPI package supports, so it's already "in the wild". If there are build failures with a specific version of JupyterLab, we should fix those directly. When the extension is installed in JupyterLab, it will provide its own versions of these packages, after all!

@tavin

tavin commented May 15, 2023

Copy link
Copy Markdown
Contributor

When the extension is installed in JupyterLab, it will provide its own versions of these packages, after all!

True. Should the yarn lockfile be removed from git and gitignored? Otherwise it somehow still seems wrong to me to have all these 3.6.3 versions in the yarn lockfile.

Edit 1: Ah looks like you fixed that (except for markdownviewer).

Edit 2:

We want to support all versions of JupyterLab greater than our lower bound. Therefore, I think we don't even want to pin these deps during development, as it means we'll catch these kinds of failures before someone installs the package in whichever JupyterLab is misbehaving.

@agoose77 I like that philosophy but I think it won't happen unless the yarn lockfile is actually removed from version control?

@agoose77

agoose77 commented May 15, 2023

Copy link
Copy Markdown
Collaborator Author

@agoose77 I like that philosophy but I think it won't happen unless the yarn lockfile is actually removed from version control?

Yes, for the most part this is true. In general, my aversion to resolutions is that they're used to fix broken package.jsons rather than specify our own constraints. However, I'm actually not aware of any projects that drop their yarn.lock, meaning that existing extensions are all working on a single lockfile, and hoping that semver protects them from breakages. This is interesting, and I suppose the main benefit is much speedier CI!

As such, unless @rowanc1 has any reservations, I'd prefer to continue working with a central lockfile that we'll keep up to date, and we'll open bug reports if something breaks within our constraints.

@agoose77 agoose77 requested a review from rowanc1 May 15, 2023 09:39
@tavin

tavin commented May 15, 2023

Copy link
Copy Markdown
Contributor

As such, unless @rowanc1 has any reservations, I'd prefer to continue working with a central lockfile that we'll keep up to date, and we'll open bug reports if something breaks within our constraints.

So upgrading most/all of the libraries in the yarn lockfile was the intention (I now see this has been done on the main branch)? Sorry I did not realize that's what you wanted, it's a different approach than what I had in mind (i.e. keeping them locked to the lower bound). Thanks for the background!

@agoose77

agoose77 commented May 15, 2023

Copy link
Copy Markdown
Collaborator Author

Sorry I did not realize that's what you wanted

No need to apologise for a good discussion.

I'm not a JS developer by trade, so take this with a pinch of salt. My contention is that the actual locked versions don't matter, as long as they work. What matters is our package.json, which describes the set of versions of our dependencies that we support. When it comes to the built package, JupyterLab (via module federation) deduplicates dependencies and applies its own rules to determine which versions of our dependencies we ultimately load.

So, I'm viewing the lockfile as "ensure everyone's working with the same dependencies", which is not entirely useful as we're developing a library/plugin rather than a standalone application, but is the typical workflow.

@tavin

tavin commented May 15, 2023

Copy link
Copy Markdown
Contributor

@agoose77 My concern was basically being unable to build the project without a magic lockfile :)
I think I'm happy if either the lockfile is pinned to the lower bounds or upgraded all the way to the latest. So I'm good now.

@agoose77

agoose77 commented May 15, 2023

Copy link
Copy Markdown
Collaborator Author

To be clear on my position here —

build the project without a magic lockfile :)

should never fail either; it should be that whatever lockfile you have, the build succeeds. If that fails, we don't support what we say we support, and should fix it!

In any case, let's see how things go :)

@rowanc1

rowanc1 commented May 15, 2023

Copy link
Copy Markdown
Member

Just a quick note to apologize for my lack of attention over in this repo! @tavin it has been great working with you over in the theme, and exciting to see that the work can come over here easily with proofs and all the style updates.

I am on vacation the next week and a bit, so hopefully won't be checking GitHub that much. Hoping when I get back to give this repo a bit more of my time!

@agoose77 agoose77 marked this pull request as ready for review May 22, 2023 08:35
@agoose77

Copy link
Copy Markdown
Collaborator Author

In the interest of getting JupyterLab 4.x working, I'm going to merge this. It appears to work!

@agoose77 agoose77 merged commit daab803 into jupyter-book:main May 30, 2023
@agoose77 agoose77 deleted the feat-mime-renderer branch May 30, 2023 11:16
@rowanc1

rowanc1 commented May 30, 2023

Copy link
Copy Markdown
Member

Excited to try this!

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.

myst renderer should take over markdown viewer as well

3 participants