접기 ​

짧은 요약과 본문을 한 블록으로 묶습니다. 툴바에서 만들면 먼저 요약을 입력하고 그 아래에 내용을 이어 쓸 수 있습니다.

삼각형으로 정한 펼침 상태는 문서에 저장되어 발행 화면의 처음 상태가 됩니다. 편집 중에도 삼각형을 눌러 열고 닫을 수 있습니다.

표 셀이나 다른 블록 안에서도 해당 접기 블록만 열고 닫습니다. 닫히는 본문 안에 커서나 선택이 있으면 밖으로 옮기고, 다른 위치에 있던 선택은 유지합니다.

wing
기본 서체높이
HTML에디터를 불러오는 중…
JSON나비트리에디터를 불러오는 중…
설치
npm install nabi-note
코드
import {
  createLocale, createNabiWith, mountSurface, mountToolbar,
  mountContextToolbar, mountHints, watchSettle, quoteWing, detailsWing,
  codeWing, mountViewTools,
} from 'nabi-note'

const selected = [
  quoteWing,
  detailsWing,
  codeWing,
]
const locale = createLocale('ko')
const { nabi, registry } = createNabiWith(selected, { locale })

// 색칠은 호스트의 하이라이터가 한다 (Prism·highlight.js·Shiki…) — wing 은 그대로 두고
// 붙는 일(attach)만 갈아 낀다 — `makeCodeAttach` 도 같은 문에서 나온다
// { ...codeWing, attach: makeCodeAttach({ highlight: (source, lang) => [{ text: source }] }) }

const root = document.querySelector('.nabi')!
const content = document.querySelector('.nabi-content')!

// locale 이 글의 방향도 정한다 — 아랍어·우르두면 오른쪽에서 왼쪽으로 선다
mountSurface({ nabi, registry, root: content, locale })

const settle = watchSettle(document, { surface: content })
const shared = { nabi, registry, surface: content, settle, locale }
const toolbar = mountToolbar({ ...shared, root: document.querySelector('#toolbar')! })
const context = mountContextToolbar({ ...shared, root: document.querySelector('#context')! })
mountHints({ toolbar, context, root, surface: content })
// 미리보기·전체화면 두 단추 — 툴바 줄의 끝에 제 상자를 세워 앉는다
mountViewTools({ ...shared, root, container: document.querySelector('#toolbar')! })

// 값이 바뀔 때마다 — 여기에 당신의 코드를 건다
// nabi.onChange(() => user_callback(nabi.getHtml()))

// 언어 선택 이벤트에서 호출한다. 내용과 편집 이력은 유지된다.
// locale.setLocale('ko')
ts
const selected = wings().use('details').build()

CSS 스타일 ​

접기 블록은 .nabi-content details, 제목은 .nabi-content details > summary로 꾸밀 수 있습니다.

css
.article-body details {
  padding: .75rem 1rem;
  border: 1px solid var(--nabi-line);
  border-radius: var(--nabi-radius);
  background: var(--nabi-soft);
}

.article-body details > summary { cursor: pointer; font-weight: 700; }
.article-body details[open] > summary { margin-block-end: .75rem; }

open 속성은 작성자가 저장한 처음 펼침 상태입니다. CSS는 이 상태를 꾸밀 수 있지만 상태를 강제로 바꾸지는 않는 편이 좋습니다.