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

Update to marked 7.0.2, add mermaidjs 10.3.1 #14102

Merged
merged 73 commits into from Aug 23, 2023

Conversation

bollwyvl
Copy link
Contributor

@bollwyvl bollwyvl commented Feb 28, 2023

References

Code changes

  • update to marked 7.0.2
    • add marked-mangle and marked-gfm-heading-id to squash deprecation warnings hard fails
  • lazily load marked
  • add mermaidjs 10.3.1
    • for parity with GitHub and GitLab
    • personally, prefers myself some graphviz, and even pikchr is pretty cool, but i digress...
  • lazily load mermaid if it's found in a GitHub/GitLab compatible code block
    • draw with appropriate stock theme (default or dark)
      • match the UI font family (ick, default trebuchet?)
    • use all available security measures
      • of course, nothing is perfect, but as it's inside an <img> tag, there's not much it can do other than load external images/style
        • this does mean some of the fancier tooltips, links and events don't work
  • rework highlighting to work with newer async-first API
  • use a reasonably-sized cache (256) for highlights and diagram renders
    • these create real DOM nodes, which is expensive

  • render text/vnd.mermaid and claim extensions .mmd and .mermaid (both supported by GitHub)
    • adds the version of mermaid rendered as jp-mermaid-version and #/metadata/text/vnd.mermaid/version
  • adds a Mermaid Copy Diagram Source context item for markdown and MIME items
    • the native context menu would already allow for copying the image with the browser's clipboard

User-facing changes

  • startup might be slightly faster, as the 39.2 kB of marked is deferred
    • though probably something draws some markdown really early
  • the downloaded wheel will be larger
    • mermaid ships a number of heavyweight libs (elkjs, parts of cytoscope, much of d3)
note shot
uses default theme with Light image
uses dark theme with Dark image
failures aren't great image
elkjs is 1.4mb to load, but is great image
cached (non-mermaid) syntax highlighting image
markdown and MIME source can be copied in the context menu image

Backwards-incompatible changes

  • n/a, aside from any breaking changes upstream 😓

Future Work

  • I haven't gotten my feet wet with CodeMirror 6 syntax themes, but even a weak mermaid grammar would improve the authoring experience
  • Many of these features could be extensible
    • adding more diagram formats, e.g. graphviz, pickchr
  • or configurable
    • e.g. render cache size

@jupyterlab-probot
Copy link

Thanks for making a pull request to jupyterlab!
To try out this branch on binder, follow this link: Binder

@tonyfast
Copy link
Contributor

🔥 this is my favorite feature from https://github.com/agoose77/jupyterlab-markup and would be 👌 to have in core.

@github-actions github-actions bot added Design System CSS tag:CSS For general CSS related issues and pecadilloes labels Feb 28, 2023
@bollwyvl bollwyvl marked this pull request as ready for review February 28, 2023 06:12
@bollwyvl
Copy link
Contributor Author

bollwyvl commented Feb 28, 2023

Oops broke syntax highlighting 😊

Update: resolved, screenshot added.

@bollwyvl
Copy link
Contributor Author

I'm actually somewhat surprised the image diffs are as small as they are:

image

image

@bollwyvl
Copy link
Contributor Author

bot please update snapshots

@bollwyvl
Copy link
Contributor Author

Yeah, I don't know what's going on with the ui screenshots.

@bollwyvl bollwyvl force-pushed the add-mermaid-to-marked branch 2 times, most recently from b56e6cd to 8fcd4d7 Compare March 1, 2023 02:22
@jtpio jtpio mentioned this pull request Mar 1, 2023
@jtpio jtpio added this to the 4.0.0 milestone Mar 1, 2023
@bollwyvl bollwyvl changed the title Update to marked 5.1.2, add mermaidjs 10.3.0 Update to marked 7.0.2, add mermaidjs 10.3.1 Aug 14, 2023
@bollwyvl
Copy link
Contributor Author

marked now uses a semi-weird pattern of declaring multiple, sythetic, un-namespaced modules like Tokens and MarkedOptions which break the import-parsing mechanism in integrity.

We already have a list of unused packages: would it be reasonable to skip dependency analysis on them, if found?

@bollwyvl
Copy link
Contributor Author

bollwyvl commented Aug 14, 2023

We already have a list of unused packages

... and missing, apparently 33eaef3 😊

This kinda seems like something that could be added to the package.json#/jupyterlab schema, and declared per-package rather than hard-coded... e.g.

"jupyterlab": {
  "integrity": {
    "missing": ["Tokens", "MarkedOptions"],
    "unused": ["marked-gfm-heading-id", "marked-mangle"]
  }
}

@bollwyvl
Copy link
Contributor Author

Binder is also busted again: jupyterhub/repo2docker#1301

Going to let ui tests give me some screenshots, then will change the pin to... something that works.

@bollwyvl
Copy link
Contributor Author

Welp, binder got past the build, showing:

/srv/conda/envs/notebook/share/jupyter/labextensions
        jupyter-offlinenotebook v0.2.2 enabled  X
        jupyterlab_pygments v0.2.2 enabled  X (python, jupyterlab_pygments)
        jupyterlab-link-share v0.2.5 enabled  X (python, jupyterlab-link-share)
        @jupyter-widgets/jupyterlab-manager v5.0.7 enabled  X (python, jupyterlab_widgets)
        @jupyter-server/resource-usage v0.7.1 enabled  X (python, jupyter-resource-usage)
        @jupyterhub/jupyter-server-proxy v4.0.0 enabled  X
        @jupyter/collaboration-extension v1.1.0 enabled OK (python, jupyter_collaboration)


   The following extensions are outdated:
        jupyter-offlinenotebook
        jupyterlab_pygments
        jupyterlab-link-share
        @jupyter-widgets/jupyterlab-manager
        @jupyter-server/resource-usage
        @jupyterhub/jupyter-server-proxy

@fcollonval
Copy link
Member

Merging and doing a release to publish a first version of the new packages.

@bollwyvl thanks a lot for the patience 🙇

@fcollonval fcollonval merged commit 07f385d into jupyterlab:main Aug 23, 2023
70 of 79 checks passed
autoStart: true,
optional: [IThemeManager],
provides: IMermaidManager,
activate: (app: JupyterFrontEnd, themes: IThemeManager) => {
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this could have been the following since IThemeManager is declared as optional:

activate: (app: JupyterFrontEnd, themes: IThemeManager | null) => {

Copy link
Member

Choose a reason for hiding this comment

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

Opened #15003

@startakovsky
Copy link

startakovsky commented Sep 19, 2023

@bollwyvl I love that this is finally merged -- is there any documentation for this extension? Thank you (I have installed it and I see it is installed (it's a brand new venv for me, but the link goes to the main jupyterlab documentation and mermaid isn't in the search results for a documentation search)

image

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

Successfully merging this pull request may close these issues.

None yet

6 participants