返回介绍

Spell Checker plugin

发布于 2019-05-06 06:50:40 字数 5960 浏览 969 评论 0 收藏 0

This plugin enables TinyMCE’s spellcheck functionality. It also adds a toolbar button and the menu item Spellcheck under the Tools menu dropdown.

Type: String

Example
tinymce.init({
  selector: "textarea",  // change this value according to your HTML
  plugins: "spellchecker",
  menubar: "tools",
  toolbar: "spellchecker"
});

Options

These settings affect the execution of the spellchecker plugin by modifying how spellchecking is handled. If you need an introduction to setting up server-side spell checking with TinyMCE please refer to this section in the General Configuration Guide.

spellchecker_callback

This option lets you override the default server side request/communication logic for the spellchecker.

Example of a basic override without using a server

tinymce.init({
  selector: "textarea",  // change this value according to your HTML
  plugins: "spellchecker",
  menubar: "tools",
  toolbar: "spellchecker",
  spellchecker_callback: function (method, text, success, failure) {
    var words = text.match(this.getWordCharPattern());
    if (method === "spellcheck") {
      var suggestions = {};
      for (var i = 0; i < words.length; i++) {
        suggestions[words[i]] = ["First", "Second"];
      }
      success({ words: suggestions, dictionary: [ ] });
    } else if (method === "addToDictionary") {
      // Add word to dictionary here
      success();
    }
  }
});

Example of fallback for the older JSON-RPC based format

tinymce.init({
  selector: "textarea",  // change this value according to your HTML
  plugins: "spellchecker",
  menubar: "tools",
  toolbar: "spellchecker",
  spellchecker_callback: function (method, text, success, failure) {
    if (method === "spellcheck") {
      tinymce.util.JSONRequest.sendRPC({
        url: "/tinymce/spellchecker.php",
        method: "spellcheck",
        params: {
          lang: this.getLanguage(),
          words: text.match(this.getWordCharPattern())
        },
        success: function (result) {
          success(result);
        },
        error: function (error, xhr) {
          failure("Spellcheck error:" + xhr.status);
        }
      });
    } else {
      failure('Unsupported spellcheck method');
    }
  }
});

spellchecker_language

This configuration option lets you set the default language code for the spellchecker. This defaults to “en”.

Type: String

Default Value: en

Example
tinymce.init({
  selector: "textarea",  // change this value according to your HTML
  plugins: "spellchecker",
  menubar: "tools",
  toolbar: "spellchecker",
  spellchecker_language: 'sv_SE'
});

spellchecker_languages

This option lets you specify a list of languages for the user to select from. The list is added to the spellcheck toolbar icon. The format is based on the 3.x spellchecker format.

Type: String

Default Value: 'English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr_FR,' + 'German=de,Italian=it,Polish=pl,Portuguese=pt_BR,Spanish=es,Swedish=sv'

Example
tinymce.init({
  selector: "textarea",  // change this value according to your html
  plugins: "spellchecker",
  menubar: "tools",
  toolbar: "spellchecker",
  spellchecker_languages: 'English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr_FR,' + 'German=de,Italian=it,Polish=pl,Portuguese=pt_BR,Spanish=es,Swedish=sv'
});

spellchecker_rpc_url

This options enables you to specify a custom URL to be used for the spellchecker. This can be the spellchecker URL provided by the TinyMCE spellchecker packages or a URL to a page that you have in your system. The URL is relative to the spellchecker plugin.

Type: String

Example
tinymce.init({
  selector: "textarea",  // change this value according to your HTML
  plugins: "spellchecker",
  menubar: "tools",
  toolbar: "spellchecker",
  spellchecker_rpc_url: 'spellchecker.php'
});

Spellchecker request format

The request is a HTTP POST with URL encoded parameters described below.

ParameterDescription
methodDefault to “spellcheck” might be other things in the future for storing custom dictionaries etc.
textText to spellcheck this will contain a plain text version of the current editor contents.
langThe currently selected language code for example “en” or “sv_SE”.

Spellchecker response format

The response of a successful spellcheck request should like this:

{
  "words": {
     "misspelled1": ["suggestion1", "suggestion2"],
     "misspelled2": ["suggestion1", "suggestion2"]
  }
}

And if there was an error:

{
  "error": "Error message"
}

spellchecker_wordchar_pattern

This option enables you to override the matching of characters that are parts of words. By default it will treat anything that isn’t a space, comma, dot, dash, quote, etc, as parts of a word. For some languages or environments it might be useful to override this behavior.

Type: String

Example
tinymce.init({
  selector: "textarea",  // change this value according to your HTML
  plugins: "spellchecker",
  menubar: "tools",
  toolbar: "spellchecker",
  spellchecker_wordchar_pattern: /[^\s,\.]+/g
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文