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

Improve Markdown + Components usage #3410

Merged
merged 12 commits into from
May 24, 2022
Merged

Improve Markdown + Components usage #3410

merged 12 commits into from
May 24, 2022

Conversation

natemoo-re
Copy link
Member

@natemoo-re natemoo-re commented May 19, 2022

Changes

  • Significantly improved component + JSX expression handling in @astrojs/markdown-remark
    • Borrows heavily from MDX and remark-mdx, but doesn't use all of the features (namely inline esm imports)
    • Only caveat to callout—shorthand attributes are not currently supported. Otherwise this a MASSIVE improvement for our components-in-markdown story.
  • Adds support for header slugs which contain JSX expressions
  • Closes 🐛 BUG: Components with array-like prop fail to render in Markdown #2399, all components inside of Markdown now have correct prop serialization
  • Removes need for extra newlines inside of Component before switching back to Markdown
  • Removes wrapping <p> tags around Components

Testing

  • Adds test suite to @astrojs/markdown-remark
  • Updates a JSX expression test in astro to reflect new and improved output

Docs

TODO

@changeset-bot
Copy link

changeset-bot bot commented May 19, 2022

🦋 Changeset detected

Latest commit: 3285844

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
astro Patch
@astrojs/markdown-remark Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

@tony-sull tony-sull left a comment

Choose a reason for hiding this comment

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

I'm not as familiar with some of the custom MD parsing logic updated here, but the test coverage looks good to me!

Marking this review as a comment rather than Approve in case anyone that's worked on the MD logic recently wants to chime in

packages/markdown/remark/src/index.ts Outdated Show resolved Hide resolved
@tony-sull tony-sull self-requested a review May 20, 2022 19:29
let { data: frontmatter, content: markdownContent } = matter(source);

// Turn HTML comments into JS comments
markdownContent = markdownContent.replace(/<\s*!--([^-->]*)(.*?)-->/gs, (whole) => `{/*${whole}*/}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 👏

Copy link
Contributor

@bholmesdev bholmesdev left a comment

Choose a reason for hiding this comment

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

REMARKABLE WORK!

@aFuzzyBear
Copy link
Contributor

I have one question. Would this allow for components in markdown files that are placed elsewhere outside of the src/pages/ to work as well. So for those projects that have a top-level docs folder in there monorepo setup, with components being relative to the markdown file, would they be able to now benefit from having components in markdown or are they still plain markdown files?

Otherwise this looks amazing, great work dude 💚💚💚
(Kinda have this thing where markdown shouldnt be in the UI )

@natemoo-re
Copy link
Member Author

natemoo-re commented May 24, 2022

I have one question. Would this allow for components in markdown files that are placed elsewhere outside of the src/pages/ to work as well? @aFuzzyBear

These changes don't touch our routing logic, just the markdown processing itself. Please open an issue detailing your use case so we can track this separately!

@natemoo-re natemoo-re merged commit cfae976 into main May 24, 2022
@natemoo-re natemoo-re deleted the fix/md-serializer branch May 24, 2022 22:02
@github-actions github-actions bot mentioned this pull request May 24, 2022
SiriousHunter pushed a commit to SiriousHunter/astro that referenced this pull request Feb 3, 2023
* feat: use internal MDX tooling for markdown + components

* fix: improve MD + component tests

* chore: add changeset

* fix: make tsc happy

* fix(withastro#3319): add regression test for component children

* fix(markdown): support HTML comments in markdown

* fix(withastro#2474): ensure namespaced components are properly handled in markdown pages

* fix(withastro#3220): ensure html in markdown pages does not have extra surrounding space

* fix(withastro#3264): ensure that remark files pass in file information

* fix(withastro#3254): enable experimentalStaticExtraction for `.md` pages

* fix: revert parsing change

* fix: remove `markdown.mode` option
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: markdown Related to Markdown (scope) pkg: astro Related to the core `astro` package (scope)
Projects
None yet
5 participants