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

Allow code snippets to be in separate files #211

Closed
alpinegizmo opened this issue Jun 27, 2022 · 3 comments · Fixed by #214
Closed

Allow code snippets to be in separate files #211

alpinegizmo opened this issue Jun 27, 2022 · 3 comments · Fixed by #214

Comments

@alpinegizmo
Copy link

alpinegizmo commented Jun 27, 2022

We want to keep the code examples used in our documentation in their own files so we can use a CI/CD pipeline that tests that the examples actually work. For example, we've done this in the past with CodeSurfer:

```java 1:7 file=../examples/example.java

And with Docusaurus, this works:

import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'
import CodeBlock from '@theme/CodeBlock'
import KafkaSinkSQL from '!!raw-loader!./KafkaSink.sql'
import KafkaSinkJava from '!!raw-loader!./KafkaSink.java'

<Tabs>
<TabItem value="sql" label="SQL">
<CodeBlock language='sql' default>{KafkaSinkSQL}</CodeBlock>
</TabItem>
<TabItem value="java" label="Java">
<CodeBlock language='java'>{KafkaSinkJava}</CodeBlock>
</TabItem>
</Tabs>

Perhaps this can already be done somehow with codehike, but if so, I haven't been able to figure it out.

@pomber
Copy link
Contributor

pomber commented Jun 27, 2022

That's something I'm planning to add soon :)

@pomber
Copy link
Contributor

pomber commented Jul 3, 2022

The syntax will be like this:

```py
# from ./assets/foo.py
```

```js
// from ./assets/foo.js
```

the imported code path is relative to the mdx file path.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 5, 2022

🚀 Issue was released in v0.6.2 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants