書体

選択した文字に書体ファミリーを適用します。範囲を選択している場合はその範囲だけを変え、キャレットだけがある場合は現在の段落の文字に適用します。実際のフォントファイルと font-family はサービス側の CSS が決めます。

基本ファミリーは sansserifmonocursive です。特に日本語を含む多言語サービスでは、各ファミリーにどのフォントを結び付けるかをあらかじめ決めておくのがよいです。

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

const selected = [
  typefaceWing,
  fontSizeWing,
  dropCapWing,
]
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('tf', {
  values: ['sans', 'serif', 'mono'],
}).build()

values を省略すると、基本ファミリーをすべて使います。values に入れた値だけが文書で許可されます。

CSS スタイル

文書にはファミリー名だけが保存され、フォントファイルは CSS が決めます。エディターと公開画面の同じコンテナーで変数を変更してください。

css
.nabi-content {
  --nabi-font-serif: "Noto Serif", "Noto Serif JP", serif;
  --nabi-font-mono: "JetBrains Mono", monospace;
}

Web フォントを使う場合は、そのフォントファイルも先に読み込む必要があります。cursive は多くの言語で十分な対応フォントがないことが多いため、サービスで実際に使うフォントを指定してから提供するのがよいです。