Code

코드 컴포넌트에 대한 문서 및 예제입니다.

사용 시기

튜토리얼이나 문서 등에서 구문 강조 표시가 포함된 소스 코드를 표시하려는 경우.

사용 예시

javascript
console.log('Hello World');

줄 번호 표시

`showLineNumbers={true}`를 전달하여 줄 번호를 활성화할 수 있습니다.

greet.js
function greet(name) {
  console.log(`Hello, ${name}!`);
}

greet('World');

헤더 및 복사 버튼 숨기기

`copyButton={false}`를 사용하여 복사 버튼을 비활성화하고 `showHeader={false}`를 사용하여 헤더를 완전히 숨길 수 있습니다.

git clone https://github.com/example/repo.git
cd repo
npm install

사용 방법

Code 컴포넌트를 사용하려면 해당 위치에서 가져오고 필요한 속성을 전달합니다.

astro
import Code from '@/components/data-display/Code.astro';

<Code
  code="console.log('Hello World');"
  language="javascript"
  showLineNumbers={true}
  filename="example.js"
/>

API 참조

속성
설명
타입
기본값

code

The source code to display. string -

language

The language of the source code for syntax highlighting. string 'javascript'

filename

The name of the file to display in the header. string -

showLineNumbers

Whether to show line numbers. boolean false

copyButton

Whether to show the copy button. boolean true

showHeader

Whether to show the header containing the filename/language and copy button. boolean true

class

Additional CSS classes to apply to the container. string -