字体

给选中文字应用字体类别。如果选中了范围,只改变该范围;如果只有光标,则应用到当前段落中的文字。实际字体文件和 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: 'zh' })

const settle = watchSettle(document, { surface: content })
const shared = { nabi, registry, surface: content, settle, locale: 'zh' }
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 SC", serif;
  --nabi-font-mono: "JetBrains Mono", monospace;
}

如果使用 Web 字体,请先加载字体文件。cursive 通常对多种语言覆盖不好,所以最好在选定服务实际使用的字体之后再提供。