Code Block
Adding codeblocks to your docs
Display code blocks, required by default.
- Syntax highlighting powered by Shiki.
- Copy button
- Custom Titles
You can add this component to mdxComponents
.
import { Pre } from 'next-docs-ui/mdx'
<MDX
components={{
pre: props => <Pre {...props} />
}}
/>
You spectify highlighted lines by adding a numbric range.
```tsx {1-2,4}
<div>Hello World</div>
<div>Hello World</div>
<div>Goodbye</div>
<div>Hello World</div>
```
You can highlight a specific word by wrapping the word in /
.
```js /config/
const config = {
reactStrictMode: true
}
```
Add title="x"
to the codeblock meta.
```js title="next.config.js"
const config = {
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
reactStrictMode: true
}
const { withContentlayer } = require('next-contentlayer')
module.exports = withContentlayer(config)
```
Inline code is supported too, console.log("Hello World")
.
`console.log("Hello World"){:js}`
const config = {
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
reactStrictMode: true
}
const { withContentlayer } = require('next-contentlayer')
module.exports = withContentlayer(config)