杂项
MDX 语法

MDX 语法

Ref: https://nextra.site/docs/guide/built-ins/steps (opens in a new tab)

Messages

import { Callout} from 'nextra/components'
 
<Callout emoji="👾">
  **Space Invaders** is a 1978 shoot 'em up arcade game developed by Tomohiro
  Nishikado.
</Callout>
👾

Space Invaders is a 1978 shoot 'em up arcade game developed by Tomohiro Nishikado.

Emoji: https://getemoji.com/assets/ (opens in a new tab)


Step

import { Steps } from 'nextra/components'
 
<Steps>
### Step 1
 
Contents for step 1.
 
### Step 2
 
Contents for step 2.
</Steps>
 

Step 1

Contents for step 1.

Step 2

Contents for step 2.


File Tree

import { FileTree } from 'nextra/components'
 
<FileTree>
  <FileTree.Folder name="pages" defaultOpen>
    <FileTree.File name="_meta.json" />
    <FileTree.File name="contact.md" />
    <FileTree.File name="index.mdx" />
    <FileTree.Folder name="about">
      <FileTree.File name="_meta.json" />
      <FileTree.File name="legal.md" />
      <FileTree.File name="index.mdx" />
    </FileTree.Folder>
  </FileTree.Folder>
</FileTree>
    • _meta.json
    • contact.md
    • index.mdx

  • Tab

    import { Tabs,Tab } from 'nextra/components'
     
    <Tabs items={['pnpm', 'npm', 'yarn']} defaultIndex="0">
      <Tab>0</Tab>
      <Tab>1</Tab>
      <Tab>2</Tab>
    </Tabs>

    Card

     
    import { Cards, Card } from 'nextra/components'
     
    <Cards>
      <Card title="Callout" href="/docs/guide/built-ins/callout" />
      <Card title="Tabs" href="/docs/guide/built-ins/tabs" />
      <Card title="Steps" href="/docs/guide/built-ins/steps" />
    </Cards>

    Code

    Inlined syntax highlighting is also supported let x = 1 via:

    Inlined syntax highlighting is also supported `let x = 1{:jsx}` via:

    js {1,4-5}

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

    js showLineNumbers

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

    js filename="example.js"

    example.js
    console.log('hello, world')

    Link

    Click [here](/about) to read more.

    等于

    import Link from 'next/link'
    Click <Link href="/about">here</Link> to read more.

    Call API

    Nextra has 13422 stars on GitHub!

    import { useData } from 'nextra/data'
     
    export const getStaticProps = ({ params }) => {
      return fetch(`https://api.github.com/repos/shuding/nextra`)
        .then(res => res.json())
        .then(repo => ({
          props: {
            // We add an `ssg` field to the page props,
            // which will be provided to the Nextra `useData` hook.
            ssg: {
              stars: repo.stargazers_count
            }
          },
          // The page will be considered as stale and regenerated every 60 seconds.
          revalidate: 60
        }))
    }
     
    export const Stars = () => {
      // Get the data from SSG, and render it as a component.
      const { stars } = useData()
      return <strong>{stars}</strong>
    }
     
    Nextra has <Stars /> stars on GitHub!