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

Markdownz: replace remark with markdownz #5352

Merged
merged 21 commits into from
Nov 1, 2023
Merged

Conversation

eatyourgreens
Copy link
Contributor

@eatyourgreens eatyourgreens commented Sep 17, 2023

Replace remark with markdownz, to parse Zooniverse markdown to HTML, and rehype, to render the parsed HTML as a React component tree.

Bump @zooniverse/react-components to 1.8.0.

Our markdown-it plugins rely on Node modules. I've added fallbacks to the dev classifier and project Webpack builds, where they require them.

Rehype 12+ is only available as ESM, so I've installed Rehype v11. Rehype is bundled with markdownz.

Package

  • app-content-pages
  • app-project
  • app-root
  • lib-classifier
  • lib-react-components

How to Review

I've updated the Markdownz Grid Example story to add various examples of Zooniverse-flavoured markdown.
http://localhost:6007/?path=/story/components-markdownz--grid-example

I've also deployed this to kubernetes, so that we can check various production projects:

Checklist

PR Creator - Please cater the checklist to fit the review needed for your code changes.
PR Reviewer - Use the checklist during your review. Each point should be checkmarked or discussed before PR approval.

General

  • Tests are passing locally and on Github
  • Documentation is up to date and changelog has been updated if appropriate
  • You can yarn panic && yarn bootstrap or docker-compose up --build and FEM works as expected
  • FEM works in all major desktop browsers: Firefox, Chrome, Edge, Safari (Use Browserstack account as needed)
  • FEM works in a mobile browser

General UX

Example Staging Project: i-fancy-cats

  • All pages of a FEM project load: Home Page, Classify Page, and About Pages
  • Can submit a classification
  • Can sign-in and sign-out
  • The component is accessible

Refactoring

  • The PR creator has described the reason for refactoring
  • The refactored component(s) continue to work as expected

@eatyourgreens eatyourgreens added the refactor Refactoring existing code label Sep 17, 2023
Comment on lines 19 to 16
expect(container.querySelectorAll('a[href]')).to.have.lengthOf(12)
expect(container.querySelectorAll('p')).to.have.lengthOf(17)
expect(container.querySelectorAll('a[href]')).to.have.lengthOf(10)
expect(container.querySelectorAll('p')).to.have.lengthOf(18)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These changes get the tests passing, but I can't figure out, from the example markdown, what the expected values really should be.

@coveralls
Copy link

coveralls commented Sep 17, 2023

Coverage Status

coverage: 82.481% (-0.04%) from 82.524% when pulling a0b2cbe on rehype-markdownz into af85940 on master.

@eatyourgreens eatyourgreens force-pushed the rehype-markdownz branch 2 times, most recently from dad57d4 to 9f05e22 Compare September 17, 2023 17:07
@goplayoutside3 goplayoutside3 self-assigned this Sep 18, 2023
@eatyourgreens
Copy link
Contributor Author

Had to install Rehype 11, because Rehype 12+ is only available as ESM.

@eatyourgreens eatyourgreens force-pushed the rehype-markdownz branch 2 times, most recently from aa48a48 to db5b846 Compare September 18, 2023 08:42
@eatyourgreens eatyourgreens marked this pull request as ready for review September 18, 2023 09:06
@eatyourgreens
Copy link
Contributor Author

eatyourgreens commented Sep 18, 2023

Rehype parses a HTML fragment as a full page, wrapped in <html>, which results in an invalid DOM. See the Rehype examples.

<html> nested inside <div> on the Gravity Spy Research page.

Fixed by explicitly setting fragment: true.

@eatyourgreens eatyourgreens force-pushed the rehype-markdownz branch 4 times, most recently from 1fabec3 to 412cf85 Compare September 18, 2023 17:17
@eatyourgreens
Copy link
Contributor Author

markdown-it was last updated a year ago. That doesn’t look good.
markdown-it/markdown-it#948

@eatyourgreens eatyourgreens force-pushed the rehype-markdownz branch 4 times, most recently from 50dd682 to 38f033f Compare September 19, 2023 16:26
@goplayoutside3
Copy link
Contributor

Re: Rehype 12+ is only available as ES -

I didn't realize that we'd run into the same headache of ESM-only package by switching to rehype so thank you for noting that right away! I think I'm hesitant about replacing remark with rehype because it seems like a temporary solution and also hesitant that markdown-it hasn't been updated recently (as you noted). What are your thoughts on FEM markdown strategy going forward? What's your opinion on switching to markdownz to address the Github Issues linked, versus sticking it out with Remark for now?

@eatyourgreens
Copy link
Contributor Author

eatyourgreens commented Sep 20, 2023

What's your opinion on switching to markdownz to address the Github Issues linked, versus sticking it out with Remark for now?

Depends on what stakeholders, which would be project teams here, expect from Zooniverse-flavoured markdown. If they expect their markdown to continue to work without changes, then markdownz will continue to parse it to the same HTML that they're already accustomed to.

With Remark, the input markdown changes and the output HTML is different, which should be summarised in ADR 11. So project teams will have to edit their existing markdown for the new parser, and we will need to document the required changes for them. We also need to install or write Remark plugins to handle custom features of Zooniverse-flavoured markdown, including:

  • username mentions.
  • subject mentions.
  • hashtag links.
  • +tab+ link syntax for new tabs.
  • [[toc]] for tables of contents.
  • custom image sizing.
  • embedded HTML5 audio and video.

My personal preference would be to leave Zooniverse-flavoured markdown unchanged if possible, so use markdownz to convert markdown to HTML.

NB. Remark uses Rehype to convert its output HTML to a React component tree, and remark-react has been replaced by rehype-react. Whether we use Remark or markdownz to parse markdown to HTML, we'll still need Rehype to map the output HTML to Zooniverse Grommet components.

Re. ESM: that's a wider issue that affects all our dependencies. This monorepo was built on CommonJS, at a time when CommonJS was being replaced by ES modules but import/export wasn't supported in Node. For example, several of the packages in the monorepo are written as CommonJS modules. These packages are all written with require and module.exports:

  • lib-async-states
  • lib-grommet-theme
  • lib-panoptes-js

The config files and custom Express servers for both NextJS apps are also written in CommonJS.

We need to be able to build and test in a world where not all of our dependencies are CommonJS any more. Whichever markdown parser we choose to use, it's not likely to be available as a CommonJS module forever. I've made markdownz available as both CommonJS and ESM since markdownz version 8. Unified packages, including Rehype and Remark, are only published as ESM.

Bun has a good summary of the current state of Node module resolution.

@eatyourgreens
Copy link
Contributor Author

eatyourgreens commented Oct 31, 2023

The new pulsars project uses a YouTube video:
https://master.pfe-preview.zooniverse.org/projects/rsengar/pulsar-seekers/about/research

I've added it to the list of examples at the top of this PR.

@goplayoutside3
Copy link
Contributor

The links to example projects are helpful - thank you! markdownz updates are looking good, and I think this PR is good to go 👍 👍 👍

Because of the change to external links (requiring +tab+ to open new browser tab), I propose this gets merged directly AFTER this week's FEM deploy. There are definitely changes to markdown behavior here that live FEM project teams should be aware of. For example, there are links in the Davy Notebooks banner (this branch, production) and the Davy Notebooks team + volunteers are accustomed to those opening in a new tab, especially from the classify page.

Let's notify the #project-building channel after this gets merged tomorrow about changes to markdown behavior going live on next FEM deploy (November 7). That'll give PMs a week or so to communicate to project teams.

@github-actions github-actions bot added the approved This PR is approved for merging label Nov 1, 2023
@eatyourgreens eatyourgreens enabled auto-merge (squash) November 1, 2023 16:55
Replace `remark` with `markdownz`, to parse Zooniverse markdown to HTML, and `rehype`, to render the parsed HTML as a React component tree.

Bump `@zooniverse/react-components` to 1.8.0.

Our `markdown-it` plugins rely on Node modules. I've added fallbacks to the dev classifier and project Webpack builds, where they require them.
8.5.0 introduces a `useMarkdownz` hook.
`markdownz` 9.0.0 includes `rehype`, so we can remove it here.
Inject parsed markdown with the `useMarkdownz` hook.
@eatyourgreens eatyourgreens merged commit b02ac8d into master Nov 1, 2023
7 checks passed
@eatyourgreens eatyourgreens deleted the rehype-markdownz branch November 1, 2023 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved This PR is approved for merging ESM refactor Refactoring existing code
Projects
3 participants