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

Unexpected characters when applying to md file #493

Closed
4 tasks done
mattrunyon opened this issue Jan 21, 2025 · 5 comments
Closed
4 tasks done

Unexpected characters when applying to md file #493

mattrunyon opened this issue Jan 21, 2025 · 5 comments
Labels
🙅 no/wontfix This is not (enough of) an issue for this project 👎 phase/no Post cannot or will not be acted on

Comments

@mattrunyon
Copy link

mattrunyon commented Jan 21, 2025

Initial checklist

Affected package

[email protected]

Steps to reproduce

  1. Open a basic test.md file in VSCode w/ the MDX extension.
  2. Put a word in the document.
  3. Change the language mode (Click Markdown in the bottom right) to MDX

Actual behavior

The MDX plugin raises errors about unknown identifiers or other ts-plugin errors.

Image

Expected behavior

The MDX plugin should work on the contents regardless of the file extension

Runtime

No response

Package manager

No response

Operating system

No response

Build and bundle tools

No response

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Jan 21, 2025
@remcohaszing
Copy link
Member

Why are you changing the language mode of a markdown file to MDX? This will break several tools.

@mattrunyon
Copy link
Author

We have a Docusaurus project that mostly has .md extensions but might use some MDX. This is supported in Docusaurus and both just compile as MDX.

I don't think changing the file language in VSCode should break other tools. A file extension doesn't guarantee the actual contents of a file. It's just a hint.

Just something I noticed when trying to use the MDX extension on .md. I don't know why it would have parsing issues just because of the file extension. You can put JS code in a .py file and tell VSCode it's JS and everything works just fine.

Also, since MDX is (mostly) a superset of MD, it should work mostly fine.

@remcohaszing
Copy link
Member

We have a Docusaurus project that mostly has .md extensions but might use some MDX. This is supported in Docusaurus and both just compile as MDX.

The MDX compiler can handle both markdown and MDX files into React components. It detects the format based on the file extension. If Docusaurus treats .md files as MDX instead of markdown, that’s a Docusaurus bug.

I don't think changing the file language in VSCode should break other tools. A file extension doesn't guarantee the actual contents of a file. It's just a hint.

Changing the language in an editor doesn’t change the build tool.

Just something I noticed when trying to use the MDX extension on .md. I don't know why it would have parsing issues just because of the file extension.

This is true to some extent. VSCode does treat a file based on the language ID. That’s why, if you change the language of a .md file to MDX, you see TypeScript errors coming from the MDX TypeScript plugin.

TypeScript however, doesn’t use these language IDs. TypeScript checking is based on file extensions. The MDX TypeScript plugin treats .mdx file in a special way. It has no knowledge of the .md file extension. So the .md file you see is being treated as if it is TypeScript.

You can put JS code in a .py file and tell VSCode it's JS and everything works just fine.

This is a good example. I created a file named test.py, changed the language to JavaScript, and added the following content:

/**
 * @returns {string}
 */
export function example() {
  return 42
}

Based on hover info and diagnostics, you can see that this is treated as TypeScript, not JavaScript. TypeScript uses the inferred return type instead of the explicit JSDoc return type, and suggests to use a TypeScript type annotation instead of a JSDoc annotation.

The code above with a hint diagnostic saying “JSDoc types may be moved to TypeScript types.ts”. The return type is number.

@remcohaszing remcohaszing closed this as not planned Won't fix, can't repro, duplicate, stale Jan 24, 2025

This comment has been minimized.

@remcohaszing remcohaszing added the 🙅 no/wontfix This is not (enough of) an issue for this project label Jan 24, 2025

This comment has been minimized.

@remcohaszing remcohaszing added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙅 no/wontfix This is not (enough of) an issue for this project 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

2 participants