-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
feat(mdx-loader): Remark plugin to report unused MDX / Markdown directives #9394
Conversation
✅ [V2]
To edit notification comments on pull requests, go to your Netlify site configuration. |
⚡️ Lighthouse report for the deploy preview of this PR
|
const warningMessage = unusedDirectives | ||
.map((unusedDirective) => { | ||
const positionMessage = unusedDirective.position | ||
? logger.interpolate`number=${unusedDirective.position.line}:number=${unusedDirective.position.column}` |
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.
Note, I'm not sure if IDEs can provide navigation if the line numbers are surrounded by ANSI sequences.
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.
For now we agreed navigation was not a goal because we need to use relative paths anyway otherwise CI tests would fail due to different absolute paths in snapshots.
And navigation apparently doesn't work in VSCode with relative paths.
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.
I've tested on VSCode and in fact there is no problem opening the file from terminal even if the path is relative or surrounded by ANSI sequences (colors in the terminal am I right?)
VSCode seems to support multiple path syntax, full path, relative with or without ./
(e.g.: ./website/README.md
or website/README.md
)
I've tested on WebStorm but it doesn't seem to have this feature (ctrl+click
) to open file in editor (not a WebStorm user so I didn't dig too much)
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.
Yes, VS Code supports opening files with paths relative to the current project. I think it even supports arbitrary paths, as long as the name is unambiguous (otherwise it shows a dropdown chooser). For example foo.tsx
can open to src/components/foo.tsx
.
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
…tives (#9394) Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
You get a warning?
If you get a warning while running your site, read this section to understand how to fix it.
TLDR:
\
to make them render as plain text\:myDirective
Problem
Docusaurus v3 uses the
remark-directive
plugin to implement Markdown Directives support.3 sort of Markdown directives exists:
:text
)::leaf
):::container
)This is how Docusaurus implements admonitions such as
:::note
or:::danger
.These directives also allow you to extend Markdown's capabilities, enabling custom functionality by providing simple Remark plugins.
Problem: if your docs already contains text like
:abc
or::xyz
, you may inadvertently use a directive, and it may not render like you expectSolution
To avoid the inadvertent usage of directive you can escape the
:
character by adding a backslash before it, or add a space after itExamples:
:text
➡️\:text
or: text
::leaf
➡️\::leaf
or:: leaf
:::container
➡️\:::container
or::: container
Motivation
This plugin aims to warn users of the usage of unused directives, to prevent mistakes and to be sure their documents keep rendering as before after upgrading to Docusaurus v3.
Test Plan
yarn jest unusedDirectives
Test links
Deploy preview: https://deploy-preview-9394--docusaurus-2.netlify.app
Related issues/PRs
remarkjs/remark-directive#12
https://talk.commonmark.org/t/generic-directives-plugins-syntax/444
https://github.com/remarkjs/remark-directive
https://docusaurus.io/docs/next/markdown-features/admonitions