jquery wordCount 中允许特殊字符和空格

发布于 2024-07-13 14:50:19 字数 1202 浏览 8 评论 0原文

我使用 jquery DynaCloud 和 wordCount 来创建动态标签云。 我有特定的术语要包含在云中(尽管每个用户的频率不同),并且某些术语是多个单词,或者具有特殊字符(“&”、“'”、“”等),例如该术语的一部分。

我用特定的 html 块来打破这些术语:

<pre><span class="tag">this isn't the last tag</span></pre>

作为示例。

wordCount 的工作方式(据我所知)是仅接受特定字符并按单词之间的空格进行分割。

我一直在尝试编辑脚本以允许所有字符(包括特殊字符),并且仅在 上中断。

然而,我所做的任何改变似乎都没有任何效果。

知道如何更改此代码以获取标签之间的所有内容并在标签上中断吗?

//accept Latin-1 basic + Latin-1 extended characters
testChar: function(c) {
    return((c >=   0 && c <= 500)
        || (c >= 128 && c <= 151)
        || (c >= 160 && c <= 164)
        || (c >=  48 && c <=  57)
        || (c >= 224 && c <= 246)
        || (c >= 249 && c <= 255));
},

//split words
splitWords: function(words) {
    var w = new Array(), str = '';
    for(var i = 0, j = words.length; i < j; i++) {
        c = words.charCodeAt(i);
        if(this.testChar(c)) str += words.substring(i, i + 1);
        else {
            w.push(str);
            str = '';
        }
    }
}

I'm using jquery DynaCloud with wordCount to create a dynamic tagcloud.
I have specific terms to include in the cloud (though the frequency is different for each user), and some of the terms are multiple word, or have special characters ("&", "'", " ", etc.) as part of the term.

I break the terms with specific html blocks:

<pre><span class="tag">this isn't the last tag</span></pre>

as an example.

The way wordCount works (as far as I can tell) is to accept only specific characters and to split on the spaces between words.

I've been trying to edit the script to allow all characters (including special), and only break on the <span class=tag>.

However, it doesn't seem that any changes I make have any effect.

Any idea how to alter this code to get everything between the tags and break on the tag?

//accept Latin-1 basic + Latin-1 extended characters
testChar: function(c) {
    return((c >=   0 && c <= 500)
        || (c >= 128 && c <= 151)
        || (c >= 160 && c <= 164)
        || (c >=  48 && c <=  57)
        || (c >= 224 && c <= 246)
        || (c >= 249 && c <= 255));
},

//split words
splitWords: function(words) {
    var w = new Array(), str = '';
    for(var i = 0, j = words.length; i < j; i++) {
        c = words.charCodeAt(i);
        if(this.testChar(c)) str += words.substring(i, i + 1);
        else {
            w.push(str);
            str = '';
        }
    }
}

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酷到爆炸 2024-07-20 14:50:19

我最终得到了这个。
我一直在尝试使用类似于脚本原作者使用的编码字符(因此c>=0 && c<=500)。 但我想太多了。

这一切都可以用简单的字符来完成,所以编辑它说

<pre>
    testChar: function(c) {
        return((c >= 97 && c <= 122)
            || (c >= 128 && c <= 151)
            || (c >= 160 && c <= 164)
            || (c >= 48 && c <= 57)
            || (c >= 224 && c <= 246)
            || (c >= 249 && c <= 255)
            || (c = "'" || " " || "&"));
    },

</pre>

现在我需要的所有字符都显示出来了。

I got this eventually.
I had been trying to use encoded characters similar to what the original author of the script used (so c>=0 && c<=500). but I was over thinking the problem.

this can all be done with just plain chacters, so edited it to say

<pre>
    testChar: function(c) {
        return((c >= 97 && c <= 122)
            || (c >= 128 && c <= 151)
            || (c >= 160 && c <= 164)
            || (c >= 48 && c <= 57)
            || (c >= 224 && c <= 246)
            || (c >= 249 && c <= 255)
            || (c = "'" || " " || "&"));
    },

</pre>

and now all the characters I need show up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文