DokumentacijaDocumentationMdxCode

Kod

Ovladavanje kodom u vašim MDX datotekama

opendocs koristi biblioteku rehype-pretty-code za obradu koda u MDX datotekama. To vam omogućuje opsežnu prilagodbu načina prikaza koda!

Za više informacija pogledajte službenu dokumentaciju i primjere!

Naslovi

Primjer:

apps/web/src/index.tsx
import { App } from './App';

Kod:

```js title="apps/web/src/index.tsx"
import { App } from './App';
```

Isticanje koda

Primjer:

module.exports = {
  theme: {
    extend: {
      colors: {
        warning: "hsl(var(--warning))",
        "warning-foreground": "hsl(var(--warning-foreground))",
      },
    },
  },
}

Kod:

```js
module.exports = {
  theme: {
    extend: {
      colors: {
        warning: "hsl(var(--warning))",
        "warning-foreground": "hsl(var(--warning-foreground))",
      },
    },
  },
}
```

Isticanje inline koda

Primjer:

Rezultat izraza [1, 2, 3].join('-') je '1-2-3'.

Kod:

The result of `[1, 2, 3].join('-'){:js}` is `'1-2-3'{:js}`.

Kontekstualno isticanje inline koda

Na primjer, ako imate sljedeći blok koda:

function getStringLength(str) {
  return str.length;
}

Kada getStringLength spominjemo kao funkciju, možemo ga tako i obojiti. Isto vrijedi za function ili str nasuprot str itd. To omogućuje semantičko povezivanje inline koda s najbližim blokom koda na koji se odnosi.

Kod:

When we refer to `getStringLength{:.entity.name.function}` as a function,
we can color it as such. Same with `function{:.keyword}`, or
`str{:.variable.parameter}` vs. `str{:.variable.other.object}`, etc. This allows
semantically link inline code to the nearest block of code it refers to.

Isticanje riječi

Primjer:

relative w-full pl-12 rounded-lg border

Kod:

```css /pl-12/ /border/
relative w-full pl-12 rounded-lg border
```

Isticanje redaka

Primjer:

module.exports = {
  theme: {
    extend: {
      colors: {
        warning: "hsl(var(--warning))",
        "warning-foreground": "hsl(var(--warning-foreground))",
      },
    },
  },
}

Kod:

```js {2-4,6}
module.exports = {
  theme: {
    extend: {
      colors: {
        warning: "hsl(var(--warning))",
        "warning-foreground": "hsl(var(--warning-foreground))",
      },
    },
  },
}
```

Numeriranje redaka

Primjer:

module.exports = {
  theme: {
    extend: {
      colors: {
        warning: "hsl(var(--warning))",
        "warning-foreground": "hsl(var(--warning-foreground))",
      },
    },
  },
}

Kod:

```js showLineNumbers
module.exports = {
  theme: {
    extend: {
      colors: {
        warning: "hsl(var(--warning))",
        "warning-foreground": "hsl(var(--warning-foreground))",
      },
    },
  },
}
```

Diff

Primjer:

const alertVariants = cva(
- "relative w-full rounded-lg border",
+ "relative w-full pl-12 rounded-lg border"
)

Kod:

```diff
const alertVariants = cva(
- "relative w-full rounded-lg border",
+ "relative w-full pl-12 rounded-lg border"
)
```

ANSI isticanje

Primjer:

  vite v5.0.0 dev server running at:
 
  > Local: http://localhost:3000/
  > Network: use `--host` to expose
 
  ready in 125ms.
 
8:38:02 PM [vite] hmr update /src/App.jsx

Inline ANSI: > Local: http://localhost:3000/

Kod:

```ansi
  vite v5.0.0 dev server running at:
 
  > Local: http://localhost:3000/
  > Network: use `--host` to expose
 
  ready in 125ms.
 
8:38:02 PM [vite] hmr update /src/App.jsx
```
 
Inline ANSI: `> Local: http://localhost:3000/{:ansi}`

Isticanje grupa riječi prema id-u

Stavite id nakon # iza riječi. To vam omogućuje da znakove obojite drukčije na temelju zadanog id-a.

Primjer:

const [age, setAge] = useState(50);
const [name, setName] = useState("Taylor");

Kod:

```js /age/#v /name/#v /setAge/#s /setName/#s /50/#i /"Taylor"/#i
const [age, setAge] = useState(50);
const [name, setName] = useState("Taylor");
```

Za promjenu ili dodavanje novih stilova:

apps/web/src/styles/mdx.css
[data-chars-id='v'] {
  @apply !text-pink-300 bg-rose-800/50 font-bold;
}