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

Treat .mdx as .md file for now #4416

Merged
merged 2 commits into from
Mar 1, 2019
Merged

Treat .mdx as .md file for now #4416

merged 2 commits into from
Mar 1, 2019

Conversation

jamiekyle-eb
Copy link
Contributor

Description

MDX (.mdx) is an superset on top of CommonMark (Markdown) that supports JSX and JavaScript's imports/exports:

I don't know what supporting the full syntax of MDX would look like for GitHub, but this will at least improve it somewhat

Syntax Example

import Layout from '../components/Layout';
import Button from '../components/Button';

export { Layout };

# Button

> A simple button component

<Button/>

<!-- Note: ^this <Button/> will be rendered -->

Checklist:

  • I am associating a language with a new file extension.
    • The new extension is used in hundreds of repositories on GitHub.com
    • I have included a real-world usage sample for all extensions added in this PR:
    • I have included a change to the heuristics to distinguish my language from others using the same extension.

MDX (.mdx) is an superset on top of CommonMark (Markdown) that supports JSX and JavaScript's imports/exports:

- MDX: https://mdxjs.com/
- CommonMark: https://commonmark.org/
- JSX: https://facebook.github.io/jsx/
- export: https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export
- import: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import

I don't know what supporting the full syntax of MDX would look like for GitHub, but this will at least improve it somewhat
@jamiekyle-eb
Copy link
Contributor Author

Note: Right now, many users are making their .mdx files use the .md file extension just so that it renders nicely on GitHub. Which is bad because the languages will become more entangled on GitHub.

This extension could be moved to another language definition later on, but for now it will cause people to use the correct file extension.

Copy link
Collaborator

@Alhadis Alhadis left a comment

Choose a reason for hiding this comment

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

This PR is missing a sample .mdx file. Could you add one under samples/Markdown/? This one will do (decent-size example, MIT-licensed).

Other than that, everything looks great. 👍

@jamiekyle-eb
Copy link
Contributor Author

@Alhadis Done!

@Alhadis
Copy link
Collaborator

Alhadis commented Feb 13, 2019

LGTM! 👍

/cc @lildude

@pchaigno
Copy link
Contributor

Looks like rendering of .mdx files with the Markdown renderer is not ideal, but might be okay. Not sure how it renders when you have a lot more JSX in there.

@Alhadis
Copy link
Collaborator

Alhadis commented Feb 14, 2019

If users are deliberately using .md just to improve the appearance of MDX files on GitHub, I'd say the less-than-ideal rendering is a loss we can take...

@pchaigno
Copy link
Contributor

@Alhadis Except they might be careful and only use .md for files that render properly, whereas we'll render everything regardless of the end result. But I agree, we should go for it, and we'll see if we need to improve that situation later.

@jamiekyle-eb
Copy link
Contributor Author

I was planning on coming back to this when I have more time to improve the situation even more. There are syntax definitions for MDX files that Linguist could use, but how GitHub renders them is a whole other question.

I'd need to figure out how to get GitHub to render a separate format as Markdown and how to make the imports/exports/jsx render as code blocks.

@Alhadis
Copy link
Collaborator

Alhadis commented Feb 14, 2019

I'd need to figure out how to get GitHub to render a separate format as Markdown and how to make the imports/exports/jsx render as code blocks.

Rendering is handled by github/markup, another Ruby gem which selects the library appropriate for rendering a document format.

Bear in mind: I don't believe the markup gem is accepting new formats, because each supported format needs to be maintained and sandboxed, and I recall reading somewhere that GitHub no longer have the manpower to achieve all this.

I'm afraid you're unlikely to have any luck, given how much of a trainwreck the NPM ecosystem is when it comes to dependencies and security.

@lildude lildude merged commit 88a2ffa into github-linguist:master Mar 1, 2019
@jamiekyle-eb jamiekyle-eb deleted the patch-1 branch March 1, 2019 18:06
@wooorm wooorm mentioned this pull request Mar 22, 2023
6 tasks
@wooorm
Copy link
Contributor

wooorm commented Mar 22, 2023

Referencing #6339, which adds a proper syntax highlighting grammar :)

wooorm added a commit to wooorm/linguist that referenced this pull request Mar 22, 2023
MDX is a literate programming language that combines markdown with
several JavaScript language features, such as JSX, expressions, and ESM.

*   markdown: <https://commonmark.org/>
*   JavaScript: <https://tc39.es/ecma262/>
*   JSX: <https://facebook.github.io/jsx/>

Previously, there was some temporary duct-tape in place, to map `.mdx`
extensions to markdown: github-linguistGH-4416.
This improved the situation from nothing to something, but has issues,
because the syntax that MDX brings wasn’t highlighted.

With this grammar, those can be properly highlighted.

Related-to: github-linguistGH-4416.
lildude added a commit that referenced this pull request May 30, 2023
* Add MDX language

MDX is a literate programming language that combines markdown with
several JavaScript language features, such as JSX, expressions, and ESM.

*   markdown: <https://commonmark.org/>
*   JavaScript: <https://tc39.es/ecma262/>
*   JSX: <https://facebook.github.io/jsx/>

Previously, there was some temporary duct-tape in place, to map `.mdx`
extensions to markdown: GH-4416.
This improved the situation from nothing to something, but has issues,
because the syntax that MDX brings wasn’t highlighted.

With this grammar, those can be properly highlighted.

Related-to: GH-4416.

* Add id

---------

Co-authored-by: Colin Seymour <[email protected]>
@github-linguist github-linguist locked as resolved and limited conversation to collaborators Jun 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants