开发者

What is a good jquery plugin to do general text processing like highlighting words and stuff like that?

开发者 https://www.devze.com 2023-02-26 02:39 出处:网络
I\'m not really too familiar with jquery plugins. I don\'t even know what I would search for, or which plugin has good activity. Jquery might even have the code built inside and I am just not aware.

I'm not really too familiar with jquery plugins. I don't even know what I would search for, or which plugin has good activity. Jquery might even have the code built inside and I am just not aware.

Basically what I'd 开发者_开发知识库like is a plugin to do some "behind the scenes" text processing - not a WYSIWYG. Things like this:

  1. Highlight words given some html or a text fragment. Basically it would let me put 'span' tags and let me wrap those words with a provided css class.

  2. Look for a word inside of a given html text, and have it give me a snippet of text where I get X characters before the word and X characters after the word with "..." on either side.

  3. A way to simply say, "Get rid of all the 'image' tags" in this text block (these are not html - just text).

Is there anything like this that is widely used, robust, etc? I'd rather not have to code this stuff from scratch.


so for your searching, jquery's really not built for the whole string manipulation thing, so i generally drop into regular old javascript and do something like this:

var search = 'some'
var matchIdx = $('body').text().search(search);
var charBefore = 5;
var charAfter = 6;
var startingIdx = matchIdx - charBefore;
var endingIdx = matchIdx + search.length + charAfter;

console.log($('body').text())
console.log(matchIdx);
console.log($('body').text().substring(startingIdx,endingIdx));

see it working in this jsfiddle


Codemirror http://codemirror.net/ is nice one. I'm using it for my projects.


Highlight plugin: http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html

0

精彩评论

暂无评论...
验证码 换一张
取 消