Skip to content

Commit 44ddc11

Browse files
committed
Fix transparent color
1 parent 5110fab commit 44ddc11

File tree

14 files changed

+322
-174
lines changed

14 files changed

+322
-174
lines changed

examples/docusaurus/docs/intro.md

Lines changed: 136 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,23 @@ sidebar_position: 1
44

55
# Code Hike + Docusaurus
66

7-
Create a Docusaurus website:
7+
You can create a new Docusaurus website with:
88

99
```
1010
npx create-docusaurus@latest my-website classic
1111
```
1212

13+
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+
1320
<CH.Scrollycoding>
1421

15-
```js docusaurus.config.js
22+
```js docusaurus.config.js focus=7
23+
/** @type {import('@docusaurus/types').Config} */
1624
const config = {
1725
presets: [
1826
// ...
@@ -32,32 +40,148 @@ const config = {
3240
module.exports = config
3341
```
3442

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
3644

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).
3846

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"]`_..
4248

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).
4450
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).
51+
---
4652

53+
```text blog/2019-05-29-long-blog-post.md focus=12
54+
---
55+
slug: long-blog-post
56+
title: Long Blog Post
57+
authors: endi
58+
tags: [hello, docusaurus]
4759
---
4860
49-
```md blog/2019-05-29-long-blog-post.md 5
5061
This is the summary of a very long blog post,
5162
5263
Use a comment to limit blog post size in the list view.
5364
5465
<!--truncate-->
5566
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+
5775
```
5876

5977
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/).
6078

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 */}`.
82+
83+
---
84+
85+
{/* prettier-ignore */}
86+
```js docusaurus.config.js focus=1:4,13:15
87+
const theme = require("shiki/themes/nord.json")
88+
const {
89+
remarkCodeHike,
90+
} = require("@code-hike/mdx")
91+
92+
/** @type {import('@docusaurus/types').Config} */
93+
const config = {
94+
presets: [
95+
[
96+
"classic",
97+
{
98+
docs: {
99+
beforeDefaultRemarkPlugins: [
100+
[remarkCodeHike, { theme }],
101+
],
102+
sidebarPath: require.resolve("./sidebars.js"),
103+
},
104+
},
105+
],
106+
],
107+
108+
themes: ["mdx-v2"],
109+
110+
themeConfig:
111+
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
112+
({
113+
navbar: {
114+
// ...
115+
},
116+
}),
117+
};
118+
119+
module.exports = config;
120+
```
121+
122+
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.
129+
130+
---
131+
132+
{/* prettier-ignore */}
133+
```js docusaurus.config.js focus=19,20,22
134+
const theme = require("shiki/themes/nord.json")
135+
const {
136+
remarkCodeHike,
137+
} = require("@code-hike/mdx")
138+
139+
/** @type {import('@docusaurus/types').Config} */
140+
const config = {
141+
presets: [
142+
[
143+
"classic",
144+
{
145+
docs: {
146+
beforeDefaultRemarkPlugins: [
147+
[remarkCodeHike, { theme }],
148+
],
149+
sidebarPath: require.resolve("./sidebars.js"),
150+
},
151+
theme: {
152+
customCss: [
153+
require.resolve("@code-hike/mdx/styles.css"),
154+
require.resolve("./src/css/custom.css"),
155+
],
156+
},
157+
},
158+
],
159+
],
160+
161+
themes: ["mdx-v2"],
162+
163+
themeConfig:
164+
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
165+
({
166+
navbar: {
167+
// ...
168+
},
169+
}),
170+
};
171+
172+
module.exports = config;
173+
```
174+
175+
Then we need to import Code Hike's stylesheet.
176+
177+
There's a `customCSS` property in the theme config. You can replace it with an array and add Code Hike's stylesheet to it.
178+
179+
If you want to customize Code Hike's styles with a global stylesheet make sure to import it after this import to avoid specificity issues.
180+
181+
You can learn more about customizing Code Hike styles in the [styling docs](/styling).
62182

63183
</CH.Scrollycoding>
184+
185+
The code for this tutorial is available on [GitHub](https://github.com/code-hike/codehike/tree/main/examples/docusaurus).
186+
187+
You can also try it out from your browser on Stackblitz.

examples/docusaurus/docusaurus.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
const lightCodeTheme = require("prism-react-renderer/themes/github")
55
const darkCodeTheme = require("prism-react-renderer/themes/dracula")
66

7+
const theme = require("shiki/themes/nord.json")
78
const { remarkCodeHike } = require("@code-hike/mdx")
8-
const theme = require("shiki/themes/monokai.json")
99

1010
/** @type {import('@docusaurus/types').Config} */
1111
const config = {
@@ -39,8 +39,8 @@ const config = {
3939
},
4040
theme: {
4141
customCss: [
42+
require.resolve("@code-hike/mdx/styles.css"),
4243
require.resolve("./src/css/custom.css"),
43-
require.resolve("@code-hike/mdx/dist/index.css"),
4444
],
4545
},
4646
}),

examples/docusaurus/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@code-hike/mdx": "^0.3.0",
1818
"@docusaurus/core": "2.0.0-beta.18",
1919
"@docusaurus/preset-classic": "2.0.0-beta.18",
20-
"@mdx-js/react": "^1.6.22",
20+
"@mdx-js/react": "^2.1.1",
2121
"clsx": "^1.1.1",
2222
"docusaurus-theme-mdx-v2": "^0.1.1",
2323
"prism-react-renderer": "^1.3.1",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Foo _`const x = 2`_ bar

packages/mdx/dev/content/scrollycoding copy.mdx

Lines changed: 0 additions & 135 deletions
This file was deleted.

packages/mdx/dev/files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from "fs"
22
import { remarkCodeHike } from "../src/index"
33
import { compile } from "@mdx-js/mdx"
4-
import theme from "shiki/themes/slack-dark.json"
4+
import theme from "shiki/themes/nord.json"
55
import { withDebugger } from "mdx-debugger"
66

77
export async function getFiles() {

packages/mdx/src/mini-editor/index.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
.ch-editor-tab {
88
border-right: 1px solid rgb(37, 37, 38);
9-
width: 120px;
9+
// width: 120px;
1010
min-width: fit-content;
1111
flex-shrink: 1;
1212
position: relative;

0 commit comments

Comments
 (0)