vitepress
vitepress copied to clipboard
Importing code snippet from jsdoc, tsdoc @example
Is your feature request related to a problem? Please describe.
It would be better to write examples in single place.
Describe the solution you'd like
Input:
<<< @/snippets/snippet-with-example.js...?
Code file:
/**
* Adds two numbers together.
*
* @example
* Here's a simple example:
* ```
* // Prints "2":
* console.log(add(1,1));
* ```
*
* @example
* Here's an example with negative numbers:
* ```
* // Prints "0":
* console.log(add(1,-1));
* ```
*/
export function add(x: number, y: number): number {
}
Output:
Here's a simple example:
// Prints "2":
console.log(add(1,1));
Here's an example with negative numbers:
// Prints "0":
console.log(add(1,-1));
Describe alternatives you've considered
No response
Additional context
No response
Validations
- [X] Follow our Code of Conduct
- [X] Read the docs.
- [X] Read the Contributing Guidelines.
- [X] Check that there isn't already an issue that asks for the same feature to avoid creating a duplicate.
This is sort of beyond the scope here. You'll probably have to use some third party library for extracting information from jsdocs comments. I'm still keeping the issue open for now.
I would love if vitepress had jsdoc drive API documentation (+ loading readme from /src) as a core feature. It would be amazing for keeping documentation in sync with code!
One can probably use Microsoft API Extractor for these kind of things. Including it in the core might get difficult for us to maintain as various users will want different sort of customizations on how docs are being extracted from comments.
Here are some example repos using api-extractor with VitePress/VuePress: https://github.com/kristiandupont/extract-pg-schema, https://github.com/kazupon/api-extractor-sandbox One can find some others too, these came on top in my search.
If someone wants to build a plugin, that'll be great too.