You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To use Code Hike we need to add these dependencies:
14
+
15
+
```
16
+
cd my-website
17
+
npm i @mdx-js/react docusaurus-theme-mdx-v2 @code-hike/mdx
18
+
```
19
+
13
20
<CH.Scrollycoding>
14
21
15
-
```js docusaurus.config.js
22
+
```js docusaurus.config.js focus=7
23
+
/**@type{import('@docusaurus/types').Config}*/
16
24
constconfig= {
17
25
presets: [
18
26
// ...
@@ -32,32 +40,148 @@ const config = {
32
40
module.exports= config
33
41
```
34
42
35
-
Code Hike requires MDX v2 but Docusaurus [doesn't support it yet](https://github.com/facebook/docusaurus/issues/4029). So we'll need to add a Docusaurus theme to support it:
43
+
## MDX v2 theme
36
44
37
-
So you install it with:
45
+
Code Hike requires MDX v2 but Docusaurus [doesn't support it yet](https://github.com/facebook/docusaurus/issues/4029). That's why we are using the [MDX v2 theme](https://github.com/pomber/docusaurus-mdx-2).
38
46
39
-
```bash
40
-
npm i docusaurus-theme-mdx-v2
41
-
```
47
+
We've already added the dependency, now we need to add the theme to the `docusaurus.config.js` with _`themes: ["mdx-v2"]`_..
42
48
43
-
And add it to your `docusaurus.config.js`with _`themes: ["mdx-v2"]`_.
49
+
> There may be a few docusaurs features that don't work with mdx v2 yet, make sure to check the [known issues](https://github.com/pomber/docusaurus-mdx-2#known-issues).
44
50
45
-
> There may be a few docusaurs features that doesn't work with mdx v2 yet, make sure to check the [known issues](https://github.com/pomber/docusaurus-mdx-2#known-issues).
Use a comment to limit blog post size in the list view.
53
64
54
65
<!--truncate-->
55
66
56
-
Lorem ipsum dolor sit amet
67
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
68
+
Pellentesque elementum dignissim ultricies. Fusce rhoncus
69
+
ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
70
+
71
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
72
+
Pellentesque elementum dignissim ultricies. Fusce rhoncus
73
+
ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
74
+
57
75
```
58
76
59
77
MDX v2 has some breaking changes in the syntax. So if you already have content using mdx v1 make sure to migrate to the new syntax. You can find [the migration guide on the mdx website](https://mdxjs.com/migrating/v2/).
60
78
61
-
If you are following this guide with the Docusaurus template the only change we need to make is one comment in the blog post `2019-05-29-long-blog-post.md`. From _`<!--truncate-->`_ to _`{/\* truncate \*/}`_.
79
+
If you are following this guide with the Docusaurus template the only change we need to make is one comment in the blog post `2019-05-29-long-blog-post.md`.
80
+
81
+
Change it from `<!--truncate-->` to `{/* truncate */}`.
Now that Docusaurus can render MDX v2 we can add Code Hike to the `docusaurus.config.js`.
123
+
124
+
We need to import the `remarkCodeHike` function from the _`@code-hike/mdx`_ package, and add it to the _`beforeDefaultRemarkPlugins`_ array.
125
+
126
+
Next to the plugin you can pass a [config object](focus://14[30:38]). Almost always you'll want to pass a theme there. You can import one from shiki, or make a custom one.
127
+
128
+
You can also pass more options, like `lineNumbers` for example. See the [configuration docs](/configuration) for more information.
0 commit comments