@farscrl/tiptap-extension-spellchecker

中文文档
2.0.2发布于 2026/07/23MITTypeScriptESM + CJS零依赖近 30 天下载 6871

A spellchecker extension for the TipTap editor

原始使用文档
文档目录13 节
  1. Installation
  2. Usage
  3. Configuration Options
  4. Commands
  5. Styling
  6. Demo
  7. Development
  8. Building
  9. Testing
  10. Linting
  11. Publishing
  12. Credits
  13. License

Tiptap Spellchecker Extension

This is an extension to integrate a spellchecker into the tiptap editor.

The extension does not implement a spellchecker itself: you have to pass it a proofreader object implementing the IProofreaderInterface interface. That proofreader can work locally in the browser, or it can call an online service, or whatever you want to use as spellchecking service.

Requires @tiptap/core ^3.0.1 (peer dependency) to already be installed in your project.

Installation

Install the dependency using npm:

npm install @farscrl/tiptap-extension-spellchecker

Or using pnpm:

pnpm add @farscrl/tiptap-extension-spellchecker

Usage

Include the extension in your tiptap editor configuration:

import { Editor } from '@tiptap/core';
import StarterKit from '@tiptap/starter-kit';
import SpellcheckerExtension, { IProofreaderInterface, ITextWithPosition } from '@farscrl/tiptap-extension-spellchecker';

const myProofreader = new Proofreader(); // implementing IProofreaderInterface

new Editor({
    extensions: [
        StarterKit,
        SpellcheckerExtension.configure({
            proofreader: myProofreader,
            uiStrings: {
                noSuggestions: 'No suggestions found'
            }
        })
    ],
});

Implement IProofreaderInterface to plug in your own spellchecking logic:

interface ITextWithPosition {
    offset: number;
    length: number;
    word: string;
}

interface IProofreaderInterface {
    // find misspelled words in a sentence
    proofreadText(sentence: string): Promise<ITextWithPosition[]>;
    // return suggestions for a misspelled word
    getSuggestions(word: string): Promise<string[]>;
    // normalize text (e.g. strip accents/casing) before it's checked
    normalizeTextForLanguage(text: string): string;
}

Configuration Options

  • proofreader (required): An object implementing the IProofreaderInterface interface
  • uiStrings (optional): Strings used for the minimal UI of the extension. If not provided, default strings are used.
  • onShowSuggestionsEvent (optional): (word: string) => void callback fired whenever the suggestion box is shown for a misspelled word

Commands

The extension registers these editor commands:

  • checkSpelling(): Re-runs the spellchecker on the whole document
  • selectAll(): Selects the entire document content
  • copy(): Copies the current selection to the clipboard
editor.commands.checkSpelling();

Styling

The extension does not ship any CSS. Misspelled words are marked with a spell-error class, and the suggestion dropdown is rendered as a #suggestions-box element containing a ul.suggestion-list — you need to add your own styles for both, otherwise the extension has no visible effect. A minimal starting point:

.spell-error {
    text-decoration: underline wavy red;
}

#suggestions-box {
    position: absolute;
    border: 1px solid black;
    background-color: #f7f7f7;
    border-radius: 4px;
}

#suggestions-box ul {
    padding: 2px 4px;
    margin: 0;
    display: inline-block;
}

#suggestions-box li {
    cursor: pointer;
    list-style: none;
}

See demo/src/css.css for a more complete example.

Demo

Two demo implementations are available in the demo folder: one using a local, in-browser dictionary (local), and one calling out to a Hunspell-based checker (hunspell). To run them:

# Clone the repository
git clone https://github.com/farscrl/tiptap-extension-spellchecker.git
cd tiptap-extension-spellchecker

# Install dependencies
pnpm install

# Build the extension
pnpm run build

# Run the demo
cd demo
pnpm install
pnpm start

The demo will open in your browser showing the spellchecker in action.

Development

Building

Build the TypeScript source:

pnpm run build

Testing

Run the test suite:

pnpm run test

Linting

Check code quality:

pnpm run lint

Publishing

To release a new version:

  1. Bump version in package.json.
  2. Add a dated entry for the new version to CHANGELOG.md.
  3. Commit both files as chore: prepare version X.Y.Z.
  4. Tag that commit: git tag vX.Y.Z and push it: git push --tags.
  5. Run npm publish (the prepare script builds lib/ automatically before publishing).

Credits

This extension is inspired by the tiptap-languagetool extension.

License

MIT

版本与发布记录

@farscrl/tiptap-extension-spellchecker 共发布 11 个版本,首次发布于 2022/08/29;过去 12 个月发布了 2 个版本。

版本发布日期距今
2.0.2latest2026/07/233 个月前
2.0.12026/04/296 个月前
2.0.02025/10/221.1 年前
1.0.72025/02/181.7 年前
1.0.62024/06/282 年前
1.0.52024/03/202 年前

关于 @farscrl/tiptap-extension-spellchecker 的常见问题

@farscrl/tiptap-extension-spellchecker 是什么?

A spellchecker extension for the TipTap editor

如何安装 @farscrl/tiptap-extension-spellchecker?

在项目目录运行 npm install @farscrl/tiptap-extension-spellchecker,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@tiptap/core(^3.0.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@farscrl/tiptap-extension-spellchecker 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@farscrl/tiptap-extension-spellchecker 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@farscrl/tiptap-extension-spellchecker 可以商用吗?

@farscrl/tiptap-extension-spellchecker 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@farscrl/tiptap-extension-spellchecker 的下载量有多少?

根据 npm 官方下载统计,@farscrl/tiptap-extension-spellchecker 在 2026/10/15 – 2026/11/13 这 30 天内被下载 6,871 次,日均约 229 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@farscrl/tiptap-extension-spellchecker 还在维护吗?

最新版本 2.0.2 发布于 2026/07/23(3 个月前);至今共发布 11 个版本,其中过去 12 个月发布了 2 个;首次发布于 2022/08/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。