Code Viewer

PRO

실행 결과와 적용 코드를 함께 보여주는 코드 문서 컴포넌트입니다.

Live preview
컴포넌트를 조작하면 여기에 결과가 표시됩니다.
코드 보기
HTML
<sy-code-viewer
  language="html"
  show-line-numbers
  show-copy-button
  collapsible
  default-expanded
  highlight-lines="1,4"
>
  <sy-code-render>
    <sy-button variant="primary">저장</sy-button>
  </sy-code-render>
  <sy-code-script></sy-code-script>
</sy-code-viewer>

사용 가이드

#

실행 결과와 소스를 보여주는 코드 문서용 컴포넌트입니다. 코드를 편집하는 에디터는 아닙니다.

미리보기와 코드

sy-code-render에 UI를, sy-code-script에 코드를 넣어 함께 보여줍니다.

코드만 표시

소스를 이스케이프한 텍스트로 전달하세요. 코드 전용 화면은 항상 펼쳐집니다.

강조와 공통 옵션
부모에서 표시 옵션을 설정하고 highlightLines에 2,4-6처럼 강조할 줄을 지정합니다.
펼침 상태
defaultExpanded는 초기 상태, expanded는 앱에서 제어할 현재 상태입니다.

기능별 예제

#

18개 주제에서 필요한 기능을 선택하세요. 속성 설정, 메서드 호출, 이벤트 결과와 슬롯 구성을 실행 화면과 코드로 확인할 수 있습니다.

사용 예제 · Overview

선택한 예제를 직접 조작해 보세요. 여러 구성이 있는 주제는 세부 예제를 바꿀 수 있습니다.

코드 보기
HTML
예제를 불러오고 있습니다.

속성 · Collapsible

설정에 따라 표시와 동작이 어떻게 달라지는지 확인하세요.

코드 보기
HTML
예제를 불러오고 있습니다.

속성 · Default Expanded

설정에 따라 표시와 동작이 어떻게 달라지는지 확인하세요.

코드 보기
HTML
예제를 불러오고 있습니다.

속성 · Highlight Lines

설정에 따라 표시와 동작이 어떻게 달라지는지 확인하세요.

코드 보기
HTML
예제를 불러오고 있습니다.

속성 · Language

설정에 따라 표시와 동작이 어떻게 달라지는지 확인하세요.

코드 보기
HTML
예제를 불러오고 있습니다.

속성 · Script Height

설정에 따라 표시와 동작이 어떻게 달라지는지 확인하세요.

코드 보기
HTML
예제를 불러오고 있습니다.

속성 · Show Copy Button

설정에 따라 표시와 동작이 어떻게 달라지는지 확인하세요.

코드 보기
HTML
예제를 불러오고 있습니다.

속성 · Show Line Numbers

설정에 따라 표시와 동작이 어떻게 달라지는지 확인하세요.

코드 보기
HTML
예제를 불러오고 있습니다.

속성 · Trigger Label

설정에 따라 표시와 동작이 어떻게 달라지는지 확인하세요.

코드 보기
HTML
예제를 불러오고 있습니다.

속성 · Wrap

설정에 따라 표시와 동작이 어떻게 달라지는지 확인하세요.

코드 보기
HTML
예제를 불러오고 있습니다.

이벤트 · Children Changed

컴포넌트를 조작하면 아래 실행 화면에 이벤트 이름과 전달 값이 표시됩니다.

코드 보기
HTML
예제를 불러오고 있습니다.

이벤트 · Code Changed

컴포넌트를 조작하면 아래 실행 화면에 이벤트 이름과 전달 값이 표시됩니다.

코드 보기
HTML
예제를 불러오고 있습니다.

이벤트 · Copied

컴포넌트를 조작하면 아래 실행 화면에 이벤트 이름과 전달 값이 표시됩니다.

코드 보기
HTML
예제를 불러오고 있습니다.

이벤트 · Expanded Changed

컴포넌트를 조작하면 아래 실행 화면에 이벤트 이름과 전달 값이 표시됩니다.

코드 보기
HTML
예제를 불러오고 있습니다.

이벤트 · Highlight Lines Changed

컴포넌트를 조작하면 아래 실행 화면에 이벤트 이름과 전달 값이 표시됩니다.

코드 보기
HTML
예제를 불러오고 있습니다.

이벤트 · Language Changed

컴포넌트를 조작하면 아래 실행 화면에 이벤트 이름과 전달 값이 표시됩니다.

코드 보기
HTML
예제를 불러오고 있습니다.

이벤트 · Line Click

컴포넌트를 조작하면 아래 실행 화면에 이벤트 이름과 전달 값이 표시됩니다.

코드 보기
HTML
예제를 불러오고 있습니다.

이벤트 · Ready

컴포넌트를 조작하면 아래 실행 화면에 이벤트 이름과 전달 값이 표시됩니다.

코드 보기
HTML
예제를 불러오고 있습니다.

API reference

#

이름에 마우스를 올리거나 키보드로 선택하면 적용 코드를 확인할 수 있습니다. 터치 화면에서는 이름을 누르세요.

<sy-code-viewer>

Properties

Attribute / PropertyTypeDefaultDescription
string'plaintext'소스 강조에 사용할 언어입니다.
booleanfalseShow line-number gutter.
booleantrueShow the copy-to-clipboard button at top-right of the source panel.
booleanfalse긴 코드 줄을 다음 줄로 감쌉니다.
string''Max-height of the script (code panel) section. Accepts any CSS length (`"320px"`, `"40vh"`, …). The live UI section and the collapse trigger are unaffected — only the code panel scrolls past this value. Renamed from the previous `maxHeight` to make the scope (script-only, not viewer-total) explicit at the call site.
string''Comma list of line numbers / ranges to emphasize. e.g. "3,5-7,12". 1-based.
booleanundefined소스 영역의 현재 펼침 상태를 외부에서 제어합니다.
booleantrue처음 표시할 때 소스 영역을 펼칩니다.
booleantrueWhen false, the trigger is hidden and the script section is forced expanded.
string'SOURCE'Text in the toggle bar.

Events

EventDetailDescription
CustomEvent<{ expanded: boolean; source: 'user' | 'prop' }>Fires whenever the viewer's expand state changes — by user click on the trigger or by the host updating the `expanded` prop. `source` distinguishes "user click" from "programmatic" for analytics consumers.
CustomEvent<{ language: string }>Fires when the `language` prop changes.
CustomEvent<{ raw: string; lines: number[] }>Fires when the `highlightLines` prop changes. Payload includes parsed line numbers.
CustomEvent<{ hasRender: boolean; hasScript: boolean }>Fires once after the viewer's first render is complete.

Slots

SlotDescription
컴포넌트의 본문 또는 자식 항목입니다.

<sy-code-render>

Properties

Attribute / PropertyTypeDefaultDescription
string''Authored markup snapshot — captured at connectedCallback time before descendants hydrate. Read by paired `<sy-code-script>` to display the user's authored markup instead of the post-hydration runtime DOM. Mutable so the component can refresh it after user-driven mutations.

Events

EventDetailDescription
CustomEvent<{ html: string }>Fires whenever the snapshot is refreshed (initial connection or a user-driven mutation that reaches the host's own child list). Paired `<sy-code-script>` listens to this event to re-render the code panel.

<sy-code-script>

Events

EventDetailDescription
CustomEvent<{ code: string; language: string }>Fires after the rendered copy button writes the code to the clipboard successfully. (Past-tense name avoids the JS property collision with the `copy` method that other web standards reserve.)
CustomEvent<{ code: string; lineCount: number; language: string }>Fires whenever the resolved code changes.
CustomEvent<{ line: number }>Fires when a line number is clicked (when `showLineNumbers` on viewer).