1

我目前正在使用https://github.com/spohlenz/tinymce-rails找到的 tinymce-rails gem ,我无法让拼写检查器初始化。TinyMCE 编辑器可以正常工作。

Javascript:

tinyMCE.init({
  mode: "specific_textareas",
  editor_selector: "tinymce",
  theme: "advanced",
  theme_advanced_toolbar_location: "top",
  theme_advanced_toolbar_align: "left",
  theme_advanced_statusbar_location: "bottom",
  theme_advanced_buttons1: "bold,italic,underline,bullist,numlist",
  theme_advanced_buttons3: "tablecontrols,fullscreen,spellchecker",
  plugins: "table,autoresize,fullscreen,spellchecker",
  width: "100%",
  height: 400,
  autoresize_min_height: 400,
  autoresize_max_height: 800,
  language:"en",
  spellchecker_languages: "+English=en"
});

erb<%= f.text_area :completed, :class => "tinymce", :size => 500 %>生成以下内容:

<body id="tinymce" class="mceContentBody " contenteditable="true" onload="window.parent.tinyMCE.get('report_completed').onLoad.dispatch();" spellcheck="false" style="overflow-y: hidden; padding-bottom: 50px;" dir="ltr">

我注意到拼写检查字段是错误的,但我不确定为什么,或者这实际上与问题有关。

4

4 回答 4

3

这篇文章这篇文章表明它比仅仅将它添加到插件列表和设置语言更复杂一些。

两篇文章都建议使用aspell检查拼写,将行添加:spellchecker_rpc_url => "/users/spellchecker",到 TinyMCE 配置,并编写一些自定义控制器代码。

我希望这些链接对您有所帮助。

于 2013-01-04T21:33:18.837 回答
3

Possible duplicate: TinyMCE 4.0.5 spell check not working

According to what I've found elsewhere, the spellchecker plugin was powered by Google service - which has been retired. So at this time there does not appear to be an integrated TinyMCE spellchecker solution.

However, you CAN enable the browser's built-in spellchecker by doing the following:

tinymce.init({
    browser_spellcheck : true,
});

Be sure to remove spellchecker from your toolbar and your plugins list.

于 2014-01-16T21:56:33.923 回答
1

只需将其添加到我的config/tinymce.yml

browser_spellcheck:
  - true
于 2014-11-10T09:57:55.017 回答
0

我最终使用了@James Chevalier链接之一中的建议,并按照TinyMCE v4 文档编写了以下内容:

# config/routes.rb

post 'tinymce/spellcheck'
# app/controllers/tinymce_controller.rb

class TinymceController < ApplicationController
  skip_forgery_protection

  respond_to :json

  def spellcheck
    suggestions = check_spelling_new(
      spellcheck_params[:text],
      spellcheck_params[:lang]
    )

    render json: {words: suggestions}
  end

  private

  def spellcheck_params
    params.permit(:method, :lang, :text)
  end

  def check_spelling_new(text, lang)
    suggestions = {}

    spell_check_response = `echo "#{text}" | aspell -a -l #{lang}`

    if spell_check_response.present?
      spelling_errors = spell_check_response.split(' ').slice(1..-1)

      spelling_errors.length.times do |i|
        spelling_errors[i].strip!

        if spelling_errors[i].to_s.start_with?('&')
          match_data = spelling_errors[i + 1]
          suggestion_count = spelling_errors[i + 2].to_i

          suggestions[match_data] ||= []

          suggestion_count.times do |k|
            suggestions[match_data] << spelling_errors[i + k + 4].gsub(',', '')
          end
        end
      end
    end

    suggestions
  end
end

// tinymce.js

tinymce.init({
  ...,
  spellchecker_rpc_url: '.../tinymce/spellcheck'
});

当然,您必须安装aspell和所需的字典。

我不建议为新项目这样做,按照@wloescher 和@Ruby Racer 所说的去做。我只为必须支持它的遗留项目这样做。

于 2020-09-04T11:47:11.247 回答