引用區塊

插件信息

引用塊用於在文件中插入引用文字並設定格式。每個引用塊帶有獨立樣式,因此引文與周圍正文的呈現明顯不同。

介紹

在 Univer Docs 中,引用塊提供以下能力:

  • 為引用文字提供獨立樣式;
  • 在塊內巢狀富文字內容;
  • 在空段落上快速退出引用格式。

外掛模式

安裝

Shell
pnpm add @univerjs-pro/docs-quote @univerjs-pro/docs-quote-ui

使用

TypeScript
import { UniverDocsQuotePlugin } from '@univerjs-pro/docs-quote'import { UniverDocsQuoteUIPlugin } from '@univerjs-pro/docs-quote-ui'import DocsQuoteUIZhTW from '@univerjs-pro/docs-quote-ui/locale/zh-TW'import { LocaleType, mergeLocales, Univer } from '@univerjs/core'import '@univerjs-pro/docs-quote-ui/lib/index.css'const univer = new Univer({  locale: LocaleType.ZH_TW,  locales: {    [LocaleType.ZH_TW]: mergeLocales(      DocsQuoteUIZhTW,     ),  },})univer.registerPlugin(UniverDocsQuotePlugin)univer.registerPlugin(UniverDocsQuoteUIPlugin)

使用 Univer 商業許可證時,配置方式參見在客戶端使用許可證。

行動裝置支援

請先完成行動版編輯器的配置。在本頁外掛模式的初始化程式碼中,將下表中的桌面版註冊替換為同一套件匯出的行動版外掛,並且必須在開啟文件前完成替換。模型外掛、樣式、語言套件和 Facade 匯入均需保留,兩個版本不要同時註冊。

套件桌面版註冊行動版註冊
@univerjs-pro/docs-quote-uiUniverDocsQuoteUIPluginUniverDocsQuoteMobileUIPlugin

Facade API

呼叫下列 API 之前,需要先匯入 facade:

TypeScript
import '@univerjs-pro/docs-quote/facade'

取得所有引用區塊

TypeScript
const doc = univerAPI.getActiveDocument()const quotes = doc?.getQuotes() ?? []

插入引用區塊

TypeScript
const doc = univerAPI.getActiveDocument()const quote = doc?.insertQuote({  startOffset: 12,  endOffset: 35,})

設定引用線顏色

TypeScript
const quote = univerAPI.getActiveDocument()?.getQuote('quote-block-id')quote?.setLineColor('#5B5FC7')

設定引用文字顏色

TypeScript
const quote = univerAPI.getActiveDocument()?.getQuote('quote-block-id')quote?.setTextColor('#242424')

你覺得這篇文檔如何?

© 2026 DreamNum Co., Ltd.