mdx-js / mdx

Markdown for the component era
https://mdxjs.com
MIT License
17.72k stars 1.14k forks source link

Markdown in code block comments #1636

Closed brillout closed 3 years ago

brillout commented 3 years ago

# Example of using markdown to define rich comments

Some code block:

```js
function hello() {
   // Example of a [url](https://example.org/) or even `inline code` defined in a comment
}
```

That would be so sweet...

While inline codes are a nice to have, URLs in comments are actually quite common.

ChristianMurphy commented 3 years ago

An interesting idea, and one which the community may be interested in!


Markdown and MDX are aware there is a code block, but they don't parse the language/content inside the block. This is not something which would make sense in MDX core.


That said, what you want could/would be possible with a plugin. Similar to how syntax highlighting can be added to codeblocks https://mdxjs.com/guides/syntax-highlighting You could create a plugin/component to parse JavaScript codeblocks, find the comments, and check the comments with a markdown parser to highlight or link the way you want.

You can find an intro to working with syntax trees and plugins at https://unifiedjs.com/learn and if you have questions on creating plugins https://github.com/mdx-js/mdx/discussions is here to help.