code-hike / codehike

Marvellous code walkthroughs
https://codehike.org
MIT License
4.41k stars 136 forks source link

Allow code snippets to be in separate files #211

Closed alpinegizmo closed 2 years ago

alpinegizmo commented 2 years ago

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 commented 2 years ago

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

pomber commented 2 years ago

The syntax will be like this:

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


the imported code path is relative to the mdx file path. 
github-actions[bot] commented 2 years ago

:rocket: Issue was released in v0.6.2 :rocket: