【问题标题】:Tinymce spell check implementationsTinymce 拼写检查实现
【发布时间】:2014-02-09 16:18:58
【问题描述】:

我有一个经典的 ASP 页面,它具有 jquery 功能并且上面有 TinyMCE 编辑器。我希望能够对编辑器进行拼写检查,但我看到的每个示例都是使用 PHP 或 ASP.net。

我遇到了这个页面:http://achorniy.wordpress.com/2009/08/11/tinymce-spellchecker-in-java/,但我对 SVN 不熟悉,所以我不确定如何执行这些步骤,而且我读过它可能不适用于 IE。

还有其他选项可以对我的 tinymce 编辑器进行拼写检查吗?

非常感谢您的帮助。

【问题讨论】:

  • @RogueSpear00 抱歉,我以为你会看到下面的注释。我得到了部分工作,但在我对 James Newtons 的 ASP 代理进行更新后,它不能正常工作。请参阅下面的我的 cmets。感谢您的跟进!我希望尽快解决这个问题

标签: jquery asp-classic tinymce


【解决方案1】:

首先,我不确定这是否可以捎带 SG 86 的答案,所以如果不是,请不要责备我......

我用SG 86的例子,发现你无法直接使用TinyMCE提供的拼写检查功能,但如果你使用论坛用户提供的hack,它确实可以成功。

  1. 安装和设置 TinyMCE
  2. 按照论坛用户的说明进行操作

TinyMCE 这个解决方案的所有功劳都应该归于原始论坛用户@http://tinymce.com/forum/viewtopic.php?id=15662


我建议首先设置 googiespell 以使用带有 asp 的简单文本区域: googiespell 在这里:http://orangoo.com/labs/GoogieSpell/

asp 脚本是 James Newtons 在此页面上的 ASP 代理:http://orangoo.com/labs/GoogieSpell/Documentation/ 因此,一旦您完成了这项工作,这就是您将其与 TinyMCE 集成的方式 在您的 javascript 设置中,拼写检查器配置:

<script language="javascript">

tinyMCE.init({
    theme : "advanced",
    mode : "textareas",
    plugins : "spellchecker",
    theme_advanced_buttons3_add : "spellchecker",
    spellchecker_rpc_url : "/googiespell/spell.asp",
    spellchecker_languages : "+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv"
});

</script>

编辑该行:

   spellchecker_rpc_url : "/googiespell/spell.asp",

指向您的 spell.asp 文件在您的应用程序中的位置

将 spell.asp 的内容替换为以下代码:

<%

Dim ByteCount, BinRead
ByteCount = Request.TotalBytes
BinRead = Request.BinaryRead(ByteCount)
rawData = RSBinaryToString(BinRead)

'get language
if instr(rawData, """params"":[""") > 1 then
    lang = mid(rawData, InStr(rawData,"[")+2, 2)
else
    lang = "en"
end if

if instr(rawData, """method"":""checkWords"",") > 1 then
'return mispelled words
 json = mid(rawData, InStrRev(rawData,"["))
 json = mid(json, 1, instr(json, "]"))
 json = replace(json, """,""", " ")
 json = replace(json, """", "")
 t = json

    r = "<?xml version=""1.0"" encoding=""utf-8"" ?><spellrequest textalreadyclipped=""0"" ignoredups=""0"" ignoredigits=""1"" ignoreallcaps=""1""><text>"_
        &t&"</text></spellrequest>"

    r = getURL("https://www.google.com/tbproxy/spell?lang="&lang, r, "","")
    out = "{""id"":null,""result"":["
    wrds = ""
    for each c in filter(split(r,"<c "),"</c>")
        'response.write "<br>"&server.htmlencode(c)
        o = cint(split(split(c,"o=",2)(1),"""")(1))+1
        l = cint(split(split(c,"l=",2)(1),"""")(1))
        s = cint(split(split(c,"s=",2)(1),"""")(1))
        out = out & """" & mid(t,o,l)& """, " 
        wrds = "1"
    next
    if wrds = "" then
        out = "{""id"":null,""result"":[],""error"":null}"
    else
        out = mid(out, 1, len(out)-2) & "],""error"":null}"
    end if

    response.write out
    response.end

else
 'return single word corrections
 json = mid(rawData, InStrRev(rawData,"["))
 json = mid(json, 1, instr(json, "]"))
 json = replace(json, """,""", " ")
 json = replace(json, "en ", "")
 json = replace(json, """", "")
 t = json

    r = "<?xml version=""1.0"" encoding=""utf-8"" ?><spellrequest textalreadyclipped=""0"" ignoredups=""0"" ignoredigits=""1"" ignoreallcaps=""1""><text>"_
        &t&"</text></spellrequest>"

    r = getURL("https://www.google.com/tbproxy/spell?lang="&lang, r, "","")

    for each c in filter(split(r,"<c "),"</c>")
        'response.write "<br>"&server.htmlencode(c)
        o = cint(split(split(c,"o=",2)(1),"""")(1))+1
        l = cint(split(split(c,"l=",2)(1),"""")(1))
        s = cint(split(split(c,"s=",2)(1),"""")(1))
        c = textbetween(">", c, "<")
        '{"id":null,"result":["Titmice","Times","Tines","Tinnies","Timmy\'s"],"error":null}
        out =  "{""id"":null,""result"":["
        wrds = ""
        for each w in split(c,vbTab)
            out = out & """" & w & """, "
            wrds = "1"
        next
        if wrds = "" then
            out = "{""id"":null,""result"":[],""error"":null}"
        else
            out = mid(out, 1, len(out)-2) & "],""error"":null}"
        end if
    next
    response.write out
    response.end
end if

 if t=empty then t = request.form()    'GoogieSpell is going to put the text in the POST data.

'show the reply from google for the POST data.     
 response.write getURL("https://www.google.com/tbproxy/spell?lang="&lang, t, "","")



Function TextBetween(sThis, sAnd, sThat)
    on error resume next
    TextBetween = split(split(sAnd,sThis,2,1)(1),sThat,2,1)(0)
end function

Function RSBinaryToString(xBinary)
  Dim Binary
  If vartype(xBinary)=8 Then Binary = MultiByteToBinary(xBinary) Else Binary = xBinary
  Dim RS, LBinary
  Const adLongVarChar = 201
  Set RS = CreateObject("ADODB.Recordset")
  LBinary = LenB(Binary)

  If LBinary>0 Then
    RS.Fields.Append "mBinary", adLongVarChar, LBinary
    RS.Open
    RS.AddNew
    RS("mBinary").AppendChunk Binary
    RS.Update
    RSBinaryToString = RS("mBinary")
  Else
    RSBinaryToString = ""
  End If
End Function

function getURL(aURL, anyPostData, anyUserName, anyPassword) 
DIM objSrvHTTP,web,method,s
    on error resume next
    s=""
    set objSrvHTTP = Server.CreateObject ("Msxml2.ServerXMLHTTP.3.0")
    if anyPostData=empty then
        objSrvHTTP.open "GET",aURL, true, anyUsername, anyPassword
    else
        objSrvHTTP.open "POST",aURL, true, anyUsername, anyPassword
        objSrvHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    end if
    objSrvHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)"
    objSrvHTTP.send anyPostData
    objSrvHTTP.waitForResponse 7
    select case objSrvHTTP.readyState
        case 0 'object created, but no URL opened
            debug "getURL("&aURL&", "&anyPostData&", "&anyUserName&", "&anyPassword&"): Object Created, no URL opened"
            err.raise 1, "Object Created, no URL opened"
            exit function
        case 1    'loading: URL opened, but no data sent
            debug "getURL("&aURL&", "&anyPostData&", "&anyUserName&", "&anyPassword&"):URL opened, no data sent"
            err.raise 2, "URL opened, no data sent"
            exit function
        case 2    'loaded: data sent, status and headers available, no response recieved.
            debug "getURL("&aURL&", "&anyPostData&", "&anyUserName&", "&anyPassword&"):No response from remote host"
            err.raise 3, "No response from remote host"
            exit function
        case 3    'interactive: some data recieved. responseBody and responseText will return partial results.
            debug "getURL("&aURL&", "&anyPostData&", "&anyUserName&", "&anyPassword&"):Partial response recieved:"
            debug server.htmlencode(objSrvHTTP.responseText)
            s = objSrvHTTP.responseText
            err.raise 4, "Partial response recieved"
        case 4    'complete: 
            s = objSrvHTTP.responseText
        end select
    getURL = s
end function

%>

编辑 - 为清楚起见添加了我的标题:

<script type="text/javascript" src="tinymce/jscripts/tiny_mce/tiny_mce.js" ></script>
<script type="text/javascript">
tinyMCE.init({
    mode : "textareas",
    theme : "advanced",
    plugins : "spellchecker",
    theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,undo,redo,|,copy,paste,|,spellchecker",
    theme_advanced_buttons2 : "",
    theme_advanced_buttons3 : "",
    spellchecker_rpc_url : "googiespell/spell.asp",  <--! Needs to point to where the spell.asp script is located on your server. -->
    spellchecker_languages : "+English=en,Spanish=es"
});

</script>

【讨论】:

  • 我不知道这个网站如何提醒 cmets 的海报,所以我只是在这里发布 SG 86 的帖子下面有 cmets,以防他们没有被看到。再次感谢你的帮助。我觉得我快要让它发挥作用了。
  • 什么不起作用?我在 SG 的回答中回答了上述问题。那没有用吗?我阅读了上周的那些 cmets 并做出了回应。
  • 不工作的部分是当我用新的 ASP 代码替换 James Newton 的 ASP 代理时。我不确定我是应该只用这个新代码编辑他的代理,还是用它完全替换它。我尝试完全替换它,并在编辑器上获得了拼写检查器,但它没有找到任何拼写更正,它用牛顿的原始代码而不是 tinymce 纠正的单词。
  • 您需要确保字典已正确启用。您使用的是哪种模式,简单模式还是高级模式?
  • 我没有编辑新的 asp 文件,我认为它的设置是为了做牛顿所做的,但能够检查 tinymce 的。所以我不确定要更改什么来启用字典,或者它处于什么模式。我会看一下它,我只是认为它已经准备好做牛顿已经在做的事情了。
【解决方案2】:

只需使用插件拼写检查器

http://www.tinymce.com/wiki.php/Plugin:spellchecker

【讨论】:

  • 感谢您的回复。我注意到了,但看到 PHP 被列为要求之一。我仍然可以在经典 ASP 中使用它吗?
  • @Cineno28 - 看起来 TinyMCE 不直接支持 Classic ASP 进行拼写检查。它使用 PHP 模块进行拼写检查。但是,对于文本框集成,它确实可以正常工作。这是他们论坛帖子之一的链接,其中包含一些您可以使用的技巧:tinymce.com/forum/viewtopic.php?id=15662
  • @Cineno28 - 我继续尝试了该链接中提供的示例,并且成功使用了 TinyMCE 拼写检查器。
  • @RogueSpear00 我不知道在哪里回复,所以我假设它就在这里,因为 SG 86 首先推荐了解决方案?我得到了使用 James Newtons 的 ASP 代理的 googiespell。然后,我尝试添加海报提供的 tinymce 和新的 ASP 脚本,但出现错误。我假设它与 getURL("google.com/tbproxy/spell?lang="&lang, r, "","") 有关。由于这是在我的服务器上,我应该将其更改为 getURL("spell.asp?lang="&lang, r , "","") 之类的?我试过了,但还是不行。
  • @RogueSpear00 同样,当它说“编辑 spell.asp 使其看起来像这样”时,是说用该代码替换整个文件,还是将其放在其中?再次感谢您的帮助。
【解决方案3】:

问题 (http://achorniy.wordpress.com/2009/08/11/tinymce-spellchecker-in-java/) 中提到的 JSpellChecker 为 TinyMCE 和使用示例提供了一些拼写检查器的实现,但它们都是基于 java 的实现(因此您需要执行一些额外的步骤才能使其在您的环境中工作)

它应该可以在 IE 上正常工作,但理想情况下,它应该与您要使用它的页面托管在同一主机上,因为浏览器(不仅是 IE)可能会阻止跨域 ajax 请求。

如果您不想处理 SVN,可以在此处下载代码快照 (http://sourceforge.net/p/jspellchecker/code/11/tarball)。它还包含使用示例

【讨论】:

    【解决方案4】:

    TinyMCE 提供

    spellchecker_rpc_url : "/myspellchcker",  
    <--! Needs to point to where the myspellchecker script is located on your server. -->
    

    这是 Python 代码(在 ASP 中编写一个等价物):

      #checker is a pyenchant object - uses enchant which wraps aspell in our case . The code was taken from django's implementation for tinymce spellchecker.
    
      def spell_check(self):
            """Returns a Response that implements the TinyMCE spellchecker protocol.
            """
            try:
                raw = self.REQUEST['BODY']
                input = json.loads(raw)
                id = input['id']
                method = input['method']
                params = input['params']
                lang = params[0]
                arg = params[1]
    
                if not enchant.dict_exists(str(lang)):
                    raise Exception("dictionary not found for language '%s'" % lang)
    
                checker = self.checker 
                if method == 'checkWords':
                    result = [word for word in arg if not checker.check(word)]
                elif method == 'getSuggestions':
                    result = checker.suggest(arg)
                elif method == 'learnWord' :
                    result = checker.add(arg)
                else:
                    raise Exception("Unkown spellcheck method: '%s'" % method)
                output = {
                    'id': id,
                    'result': result,
                    'error': None,
                }
            except Exception:
                return Exception("Error running spellchecker")
            self.REQUEST.RESPONSE.setHeader('Content-Type','application/json')
            return json.dumps(output)
    

    【讨论】:

      猜你喜欢
      • 2011-10-24
      • 1970-01-01
      • 1970-01-01
      • 2013-03-27
      • 1970-01-01
      • 2016-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多