文字サイズ

選択した文字のサイズ段階を変えます。範囲を選択している場合はその範囲に適用され、キャレットだけがある場合は現在の段落の文字サイズを変えます。保存データには px のような任意値ではなく、許可された段階だけが残ります。

ウィング
既定の書体高さ
HTMLエディタを読み込んでいます…
JSONnabi-treeエディタを読み込んでいます…
インストール
npm install nabi-note
コード
import {
  createNabiWith, mountSurface, mountToolbar, mountContextToolbar,
  mountHints, watchSettle, boldWing, italicWing, underlineWing,
  strikeWing, typefaceWing, fontSizeWing, clearFormatWing,
  mountViewTools,
} from 'nabi-note'

const selected = [
  boldWing,
  italicWing,
  underlineWing,
  strikeWing,
  typefaceWing,
  fontSizeWing,
  clearFormatWing,
]
const { nabi, registry } = createNabiWith(selected)

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

// The locale also sets the direction — Arabic and Urdu run right to left
mountSurface({ nabi, registry, root: content, locale: 'ja' })

const settle = watchSettle(document, { surface: content })
const shared = { nabi, registry, surface: content, settle, locale: 'ja' }
const toolbar = mountToolbar({ ...shared, root: document.querySelector('#toolbar')! })
const context = mountContextToolbar({ ...shared, root: document.querySelector('#context')! })
mountHints({ toolbar, context, root, surface: content })
// The preview and fullscreen buttons — they stand their own box at the end of the row
mountViewTools({ ...shared, root, container: document.querySelector('#toolbar')! })

// on every change — hook up your own code here
// nabi.onChange(() => user_callback(nabi.getHtml()))
ts
const selected = wings().use('fs', {
  values: ['sm', 'lg', 'xl'],
}).build()

values を省略すると、xssmlgxl の段階を使います。リストを絞ると、以前の文書に入っていた別の段階も読み込み時に削除されます。

CSS スタイル

サイズは .nabi-content [data-nabi-size="xs"] のように、保存された段階のセレクターで変えられます。文書にない任意の段階を作らず、登録した values の中だけで CSS を調整してください。

css
.article-body [data-nabi-size="xs"] { font-size: .78em; }
.article-body [data-nabi-size="sm"] { font-size: .9em; }
.article-body [data-nabi-size="lg"] { font-size: 1.3em; }
.article-body [data-nabi-size="xl"] { font-size: 1.65em; }

段階ごとのサイズ差を一定にしておくと、作成者がエディターで選んだ意味が公開画面でも保たれます。