Code Extensions

MDX Examples

Code extensions

````js filename="demo.js" copy {3} showLineNumbers
let a = 1;

console.log(a);
```
  • The copy directive adds a copy button to the code block.
  • THe showLineNumbers directive adds line numbers to the code block.
  • The filename directive adds a file name to the code block. At the top appears the file name.
  • The {3} directive highlights the specified line. Remarks line 3.
demo.js
let a = 1;
 
console.log(a);

Regular expressions

```js /useState/
import { useState } from 'react'
 
function Counter() {
  const [count, setCount] = useState(0)
  return <button onClick={() => setCount(count + 1)}>{count}</button>
}
``` 

You can highlight only a part of the occurrences of that substring by adding a number it: /str/1, or multiple: /str/1-3.

import { useState } from 'react'
 
function Counter() {
  const [count, setCount] = useState(0)
  return <button onClick={() => setCount(count + 1)}>{count}</button>
}

ANSI highlighting

```ansi
 ✓ src/index.test.ts (1)
   Test Files  1 passed (1)
        Tests  1 passed (1)
     Start at  23:32:41
     Duration  11ms
   PASS  Waiting for file changes...
         press h to show help, press q to quit
```
  src/index.test.ts (1)
   Test Files  1 passed (1)
        Tests  1 passed (1)
     Start at  23:32:41
     Duration  11ms
   PASS  Waiting for file changes...
         press h to show help, press q to quit

npm2yarn

Nextra uses @theguild/remark-npm2yarn (opens in a new tab) package that replaces the code block that has npm2yarn metadata with <Tabs /> (opens in a new tab) and <Tabs.Tab /> (opens in a new tab) components from nextra/components.

```sh npm2yarn
npm i -D @graphql-eslint/eslint-plugin
```
npm i -D @graphql-eslint/eslint-plugin