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

Add warning about Prettier/plain Markdown formatters in Docs about MDC syntax #1709

Closed
nwittwer opened this issue Nov 25, 2022 · 3 comments
Closed
Assignees
Labels
enhancement New feature or request

Comments

@nwittwer
Copy link

nwittwer commented Nov 25, 2022

Is your feature request related to a problem? Please describe

After installing the MDC VSCode extension and trying to re-write my .md files with the MDC syntax (moving from @nuxt/content v1 to v2), it was frustrating to try writing MDC, save, and then the code is re-formatted back to Markdown format.

The reason: I'm using Prettier for code formatting, and because the file is .md (just like normal Markdown), it has no way to know I want to use MDC syntax. Prettier's Parser automatically enables formatting on .md files.

Example (before: default Prettier, after: disabled Prettier on .md files w/ .prettierignore)
vscode-demo

Describe the solution you'd like

The Docs currently only mention installing the VSCode extension:

Install the MDC VS Code extension to get proper syntax highlighting for your MDC components.

Likely there are others who will upgrade to Content v2, are using Prettier, and will encounter a similar issue with .md be re-formatted. I know this is not really an issue on the Nuxt ecosystem side. But maybe the Docs can mention a warning about it, to make things as smooth as possible. Even better would be if the Nuxt MDC VSCode extension could provide MDC formatting, but probably that would take more time to figure out.

Suggestion: Add at least one sentence to the Docs that some additional configuration may be needed to tell VSCode which formatter to use, so that MDC is properly formatted instead of using Markdown formatting.

For example:

Install the MDC VS Code extension to get proper syntax highlighting for your MDC components.
⚠️ If you use Prettier or other code formatting extensions, see this section so your .md files with MDC syntax won't be automatically re-formatted to plain Markdown.

And a more detailed description section it links to:

Disable Markdown formatting on MDC written in.md files

Prettier and other code formatting extensions will try to format .md files to plain Markdown and not the MDC syntax. As a workaround, you can disable automatic Markdown formatting for all of the .md files where you'd like to use MDC syntax and not plain Markdown.

  • Prettier: If you're using MDC for all your .md files, create a .prettierignore file and add a new line: *.md to disable Prettier for all Markdown files. You could also configure only certain paths, e.g. /blog/**/*.md if you have some files that you'd still like to format with plain Markdown. Refer to Prettier docs.

Describe alternatives you've considered

  1. There's an open ticket on Prettier to add MDC syntax: [Markdown] Markdown components (MDC) syntax support prettier/prettier#13512. Maybe in the future there will be an easier way to indicate that an .md file is using MDC syntax and not plain Markdown?
  2. Or the Nuxt MDC VSCode extension could have its own MDC formatter which tries to override other formatters the user has installed?
  3. Or a new dedicated .mdc extension like the MDX format (.mdx) could make it easier to distinguish whether the file should be parsed as plain Markdown, MDC, etc.
@nwittwer nwittwer added the enhancement New feature or request label Nov 25, 2022
@nwittwer nwittwer changed the title Add warning about Prettier/formatters in Docs about MDC syntax Add warning about Prettier/plain Markdown formatters in Docs about MDC syntax Nov 25, 2022
Copy link
Contributor

Tahul commented Nov 27, 2022

Hey @nwittwer ; I already encountered this problem too, thank you a lot for reporting it so clearly.

@Atinux @farnabaz what are your insights?

That is something I think we should look at, at least at for a documentation section, at best a feature in MDC extension, or @nuxt/content itself?

Copy link
Member

I think we can overwrite prettier's markdown parser to use remark/mdc.
We need to research a bit prettier markdown plugin and parser. I'm not very familiar with prettier, and don't know if there is any extra markdown plugins for prettier markdown parser.
If there isn't any we can simply replace default parser with our own parser to support MDC syntax.

@Atinux Atinux removed their assignment Dec 19, 2022
@fanckush
Copy link

is there a workaround for this atm?

Triloworld added a commit to Triloworld/content that referenced this issue Sep 20, 2023
MuhammadM1998 added a commit to egytech-fyi/website-v2 that referenced this issue Jun 6, 2024
-- It isn't compatible with mdc syntax used by nuxt content (nuxt/content#1709)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants