图片

插入图片地址,并调整宽度和对齐方式。默认情况下,地址限制为 http:https: 或同站路径,新图片会以 60% 宽度居中开始。

宽度只保存为固定档位,对齐方式保存在包裹图片的段落上。要使用 blob:data:image/... 预览,需要在图片 wing 和编辑器组装处都明确允许本地 URL。不允许 SVG data URL。

翅膀
默认字体高度
HTML正在加载编辑器…
JSONnabi-tree正在加载编辑器…
安装
npm install nabi-note
代码
import {
  createNabiWith, mountSurface, mountToolbar, mountContextToolbar,
  mountHints, watchSettle, tableWings, imageWing, youtubeWing,
  mountViewTools,
} from 'nabi-note'

const selected = [
  ...tableWings,
  imageWing,
  youtubeWing,
]
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('img', {
  allowLocalUrls: false,
}).build()

这个 wing 只是把地址插入文档,并不会上传文件。要把文件发送到服务器,请连接上传 wing

CSS 样式

.nabi-content img 设置图片样式。保持保存的宽度和对齐方式不变,只改变边框或阴影等视觉细节。

css
.article-body img {
  border-radius: 12px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 12%);
}

.dark .article-body img { box-shadow: 0 8px 24px rgb(0 0 0 / 35%); }

保留 max-inline-sizeblock-size、width 和对齐方式的默认规则。图片大小保存在文档中,因此强制设置固定 CSS 宽度可能会和作者选择的宽度冲突。