
# 시작하기

## 설치

```bash
composer require shikiphp/shikiphp
```

shikiphp에는 PHP 8.2 이상과 `ext-json` 및 `ext-mbstring`이 필요합니다. 이 둘은 거의 모든 PHP 빌드에서 활성화되어 있습니다. 그 외에는 Node, 네이티브 Oniguruma 바인딩, 추가 확장이 필요 없습니다.

## 첫 코드 블록

정적 `Shikiphp` 파사드가 가장 빠른 시작 방법입니다. 코드와 언어 ID, 테마 ID를 전달하세요:

```php
use Shikiphp\Shikiphp;

$html = Shikiphp::codeToHtml(<<<'PHP'
<?php
function greet(string $name): string {
    return "Hello, {$name}!";
}
PHP, [
    'lang'  => 'php',
    'theme' => 'github-dark',
]);

echo $html;
```

`codeToHtml`는 스타일이 완성된 `<pre class="shiki …">` 블록을 반환합니다. 전경색과 배경색이 `<pre>`에 인라인으로 지정되므로 별도의 스타일시트 없이도 올바르게 렌더링됩니다.

## 이중 테마(라이트 및 다크)

단일 `theme` 대신 `themes` 맵을 전달하세요. shikiphp는 CSS 변수를 출력합니다(Shiki 등). 따라서 렌더링된 코드 블록 하나가 라이트 및 다크 모드에 맞게 바뀝니다:

```php
use Shikiphp\Shikiphp;

$code = 'const answer: number = 42';

echo Shikiphp::codeToHtml($code, [
    'lang'   => 'ts',
    'themes' => ['light' => 'github-light', 'dark' => 'github-dark'],
]);
```

기본적으로 `light` 테마의 색상이 인라인 기본값이 되고, `dark`은 `--shiki-dark` 변수로 노출됩니다. 간단한 CSS를 사용해 다크 테마를 활성화하세요. 문서의 동일한 코드 조각 Shiki를 참고하면 됩니다:

```css
html.dark .shiki,
html.dark .shiki span {
  color: var(--shiki-dark) !important;
  background-color: var(--shiki-dark-bg) !important;
  /* and font styles */
  font-style: var(--shiki-dark-font-style) !important;
  font-weight: var(--shiki-dark-font-weight) !important;
  text-decoration: var(--shiki-dark-text-decoration) !important;
}
```

[`defaultColor`](https://shikiphp.inline0.dev/ko/docs/options#defaultcolor) 옵션으로 인라인 기본 테마를 선택하거나, `defaultColor: false`를 설정해 변수만 출력할 수 있습니다.

## 언어 ID 및 별칭

언어는 Shiki ID 또는 별칭(`php`, `ts`, `js`, `rust`, `python`, `html` 등)으로 참조합니다. 번들에 포함된 전체 목록을 확인하는 방법은 [언어](https://shikiphp.inline0.dev/ko/docs/languages)를, 테마 ID는 [테마](https://shikiphp.inline0.dev/ko/docs/themes)를 참조하세요.

## 하이라이터 재사용

파사드는 번들 `Highlighter`를 지연 생성하고 캐시하므로 `Shikiphp::codeToHtml`를 반복 호출해도 동일한 문법 및 테마 캐시를 재사용합니다. HAST 출력, 사용자 지정 문법, 토큰 그리드 등 더 다양한 기능을 제공하는 API가 필요하면 인스턴스를 직접 가져오세요:

```php
use Shikiphp\Shikiphp;

$code = 'fn main() {}';

$highlighter = Shikiphp::highlighter();
$hast = $highlighter->codeToHast($code, ['lang' => 'rust', 'theme' => 'nord']);
```

전체 기능은 [API](https://shikiphp.inline0.dev/ko/docs/api)를 참조하세요.
