Skip to content

Is it possible to import code (not just entire files with the raw loader) and display in a doc block? #9710

Answered by slorber
unleashit asked this question in Q&A
Discussion options

You must be logged in to vote

you can approach this problem in multiple ways, such as creating your own raw loader that strips content outside string markers, or implementing a remark plugin.


Here's @jknoxville remark plugin that probably matches your need:
https://github.com/jknoxville/remark-code-snippets

Here's @christian-bromann remark plugin that fetches code blocks directly from a GitHub link
https://github.com/saucelabs/docusaurus-theme-github-codeblock

Not sure those solutions are compatible (yet?) with Docusaurus v3 but at least it can give you some inspiration.


Here's a tutorial on how to implement your own Webpack loader: https://webpack.js.org/contribute/writing-a-loader/

You could use this to create you…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by unleashit
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants