-
-
Notifications
You must be signed in to change notification settings - Fork 500
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
Add Markdoc preset and example #2249
Conversation
🦋 Changeset detectedLatest commit: 4bae5e3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
✅ Deploy Preview for astro-starlight ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this @HiDeoo!
Quick meta question ahead of a more thorough review: do you think this might make more sense as a standalone package Markdoc users need to install? As they will in any case need to add some manual config, the extra friction to npm i @astrojs/starlight-markdoc-preset
or whatever the package name is, doesn’t seem too bad and would help keep things separate.
Good question, I remember when we quickly discussed this we mentioned the possibility of having a dedicated package for this. The current implementation lives in the core package as it was easier to setup everything but I made sure that everything pretty much depends only on
I'm personally leaning towards having a dedicated package for this, as I like the separation (just like |
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
Updated the PR with the following changes:
|
Updated the PR to use I also took a bit of time to try the tooling and more specifically the Visual Studio Code Markdoc language extension:
Considering all this, I'm undrafting the PR to get more feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM @HiDeoo! Left a couple of tiny details but I don’t have any major feedback. I think once we have #2121 merged, it would be nice to have a MDX / Markdoc tab to show the component syntax probably?
But that’s for the future.
Edit: missed a couple of your questions in the PR comment:
- I think we might as well update
labeler.yml
to auto tag PRs for the new package 👍 - And yes, needs a changeset. A minor should trigger publishing the first release as v0.1 I think
Definitely, as soon as this PR is released, I will update #2121 to include the MDX and Markdoc syntax. It would still use the same component but with the Markdoc syntax in a new different slot (altho, the preview will still be the MDX one as this wouldn't change anything). I will also need to research a bit about Markdoc common formatting, if they tend to indent nested tags or not, etc. as I'm not familiar with it but we should provide examples in a format that is common to the users. Thanks for the review 🙌 I'll tackle the remaining points early next week. |
Co-authored-by: Chris Swithinbank <357379+delucis@users.noreply.github.com>
Co-authored-by: Chris Swithinbank <357379+delucis@users.noreply.github.com>
Co-authored-by: Chris Swithinbank <357379+delucis@users.noreply.github.com>
Just updated the PR with the discussed changes. I also took care of the remaining tasks in the PR body, created the new label (not sure if this was required or not but at least it'll have the appropriate color/description) and added a changeset. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lovely work! Ready for launch 🚀
Updated the Markdoc example to the latest Astro to match the changes in #2287 and still LGTM! |
* main: (37 commits) [ci] format i18n(ko-KR): update `manual-setup.mdx` (withastro#2294) i18n(ko-KR): update `configuration.mdx` (withastro#2295) [ci] release (withastro#2292) Add support for SSR (withastro#1255) Add Markdoc preset and example (withastro#2249) Refactor sidebar persistence logic for better slow device performance (withastro#2242) [ci] format Add docs.ryzekit.com to showcase (withastro#2291) Update astro dependency to 4.15.3 across monorepo (withastro#2289) [ci] release (withastro#2290) Prevent Zod errors from crashing build (withastro#2288) i18n(fr): update `guides/css-and-tailwind` (withastro#2286) i18n(ko-KR): update `css-and-tailwind.mdx` (withastro#2284) Add WCAG AAA colour contrast option to theme editor (withastro#2282) [ci] release (withastro#2283) Parse `<StarlightPage />` frontmatter asynchronously (withastro#2279) Ensure unhandled directives are restored without any extra whitespace (withastro#2281) i18n(fr): update `resources/plugins` (withastro#2278) i18n(ko-KR): update `plugins.mdx` (withastro#2277) ...
* main: (22 commits) i18n(ru): update `ru/manual-setup.mdx` and `ru/reference/configuration.mdx` (withastro#2307) [ci] format i18n(ru): update some guides (withastro#2306) i18n(fr): update `manual-setup` (withastro#2299) i18n(fr): update `guides/pages` (withastro#2298) [ci] release (withastro#2304) Convert URL to file path correctly for Git virtual module (withastro#2303) i18n(fr): update `reference/configuration` (withastro#2296) i18n(fr): update `guides/authoring-content` (withastro#2297) Update `yummacss.com.png` thumbnail (withastro#2301) i18n(ko-KR): update `pages.mdx` (withastro#2293) [ci] format i18n(ko-KR): update `authoring-content.mdx` (withastro#2300) [ci] format i18n(ko-KR): update `manual-setup.mdx` (withastro#2294) i18n(ko-KR): update `configuration.mdx` (withastro#2295) [ci] release (withastro#2292) Add support for SSR (withastro#1255) Add Markdoc preset and example (withastro#2249) Refactor sidebar persistence logic for better slow device performance (withastro#2242) ...
Description
This PR adds a Markdoc preset and example to Starlight so that users can more easily use or get started with Markdoc in Starlight.
Limitations
There are a few limitations in the current version due to either Markdoc itself or other constraints. They are all documented in the preset itself but I will list the most important ones here:
icon
attributes do not have an explicit set ofmatches
and just accept any string.<a>
tag,don't have the same parity in Markdoc.code
tag instead with themeta
attribute.I'll try to see if there are some valid workarounds for these limitations.
There is also an issue that we cannot use theextends
field in amarkdoc.config.mjs
file. Using it lead to anUnable to render [object Object]. No valid renderer was found for this file extension.
error.I'll have to investigate this issue further to see if it's a bug or a real limitation, e.g. maybe not being able to usecomponent
in theextends
field for some reason.Opened withastro/astro#11846 to fix this issue.
Testing
We briefly discussed about ensuring some kind of sync between Starlight user components and their tags equivalent in Markdoc. I opted to use type testing as I think it may be one of the easiest approach to this.
We can rely on the amazing
ComponentProps
type from Astro to extract user components props and TypeScript type-inference on the preset (that only usesatisfies
to keep the most specific type) to extract Markdoc tags attributes. We can then compare the two types to ensure they are in sync.At the moment, there are 2 type of type tests:
We rely on a few Vitest type testing utilities but we do not run these tests using Vitest as type tests seems a bit fragile when using Vitest workspaces, and also because Vitest would use
tsc
to run those and this would not play well with Astro components. Instead, the already existingpnpm typecheck
command will ensure these tests are valid.Documentation
Need to think a bit more about this. I think we should at least have documentation on how to use the new Markdoc preset. Not sure yet tho where this documentation should be placed, the "Authoring Content in Markdown" page may not be the best place for this.I added a new Markdoc documentation section using the same structure used for
@astrojs/starlight-tailwind
..md
to.mdx
and we know how Prettier & MDX can be a bit tricky sometimes so I wanted to make sure nothing would break when the formatter would run.Remaining tasks
extends
not rendered as Markdoc tags/nodes astro#11846 to be merged and releasedpackages/markdoc/package.json
filepeerDependencies
to use the new@astrojs/markdoc
versionexamples/markdoc/markdoc.config.mjs
to use theextends
syntaxpackages/markdoc/README.md
.github/labeler.yml
should be updatedexamples/markdoc/astro.config.mjs
examples/markdoc/src/content/docs/demo/
folder and all its content