Page 2 of 3

Re: Text Coloring

Posted: 22 Aug 2013 00:32
by Gub
For your trigger check the regular expression box, and put in (peculiar|exotic|unusual) in the box (that triggers on peculiar OR exotic OR unusual)

Code: Select all

var src_str=$("#mudoutput .line").last().html();
var pattern = new RegExp("(peculiar|unusual|exotic)", "i");
src_str = src_str.replace(pattern, "<mark>$1</mark>");
$("#mudoutput .line").last().html(src_str);
There's a simpler version. The other had a lot additional checks that I don't think will be needed.

Basically all those funny symbols are regular expressions, often referred to as "regex". Regex is super handy and great to use, but it has a little bit of a learning curve. You can try some of it out here http://regexone.com/

Re: Text Coloring

Posted: 22 Aug 2013 00:55
by Gub

Code: Select all

var src_str=$("#mudoutput .line").last().html();
var pattern = new RegExp("(peculiar|unusual|exotic)", "i");
src_str = src_str.replace(pattern, "<span style=\"color:green\">$1</span>");
$("#mudoutput .line").last().html(src_str);
This gives you a little more control over the color. Note in this code the color is green, but could be changed to anything.

Re: Text Coloring

Posted: 22 Aug 2013 02:32
by Laurel
Now ya talkin'!
I'm with Rincon on this one.

Re: Text Coloring

Posted: 22 Aug 2013 08:08
by Eowul
Nice one Gub. I am just thinking, we could send the last line (as jquery object) as one of the variables available within the trigger (like the args var that contains the original matching regexp), and then your trigger would not be using any internal API's at all.

Re: Text Coloring

Posted: 22 Aug 2013 08:36
by Gub
I'm not picturing it. What would it look like?

In my ideal world I would be making calls such as:

Code: Select all

var pattern = new RegExp("(peculiar|unusual|exotic)", "i");
gwc.output.replace(pattern, "<span style=\"color:green\">$1</span>");
I think any wrapper around the jquery calls I made would be good.

Re: Text Coloring

Posted: 22 Aug 2013 11:41
by Eowul
Gub wrote:I'm not picturing it. What would it look like?

In my ideal world I would be making calls such as:

Code: Select all

var pattern = new RegExp("(peculiar|unusual|exotic)", "i");
gwc.output.replace(pattern, "<span style=\"color:green\">$1</span>");
I think any wrapper around the jquery calls I made would be good.
You abstracted the calls even more then I had initially thought, but this sounds good .. Only question would be, would it be safe to do the replace on a .html() of the last line, if another trigger added different HTML before, it could mess things up, perhaps use .text() instead? Or would this be a 'user error' kind of thing?

Re: Text Coloring

Posted: 22 Aug 2013 22:42
by Gub
I think you may be right, it is too abstracted. Maybe something closer to this?

Code: Select all

var src_str = gwc.output.getLine();
var pattern = new RegExp("(peculiar|unusual|exotic)", "i");
src_str = src_str.replace(pattern, "<span style=\"color:green\">$1</span>");
gwc.output.replaceLine(src_str);
I could go either way on that argument. Maybe I want two triggers to alter the line twice? I think if I changed the html once, I would have to expect it to be changed moving forward and base my subsequent calls on my initial change, but thats just my stream of though. I think the argument for either case is strong. I don't know if I'd use text there, I think it'd escape the html and I wouldn't be able to use span or any html to change the line?

Re: Text Coloring

Posted: 23 Aug 2013 07:37
by Eowul
Gub wrote:I think you may be right, it is too abstracted. Maybe something closer to this?

Code: Select all

var src_str = gwc.output.getLine();
var pattern = new RegExp("(peculiar|unusual|exotic)", "i");
src_str = src_str.replace(pattern, "<span style=\"color:green\">$1</span>");
gwc.output.replaceLine(src_str);
I could go either way on that argument. Maybe I want two triggers to alter the line twice? I think if I changed the html once, I would have to expect it to be changed moving forward and base my subsequent calls on my initial change, but thats just my stream of though. I think the argument for either case is strong. I don't know if I'd use text there, I think it'd escape the html and I wouldn't be able to use span or any html to change the line?
I think text() removes the html tags,not escape then. Then, if we put the result back into the html() function, you should be able to use spans and such ... I suppose we could add it as an optional 3rd argument.

Re: Text Coloring

Posted: 25 Aug 2013 12:54
by Eowul
eowul wrote:I think text() removes the html tags,not escape then. Then, if we put the result back into the html() function, you should be able to use spans and such ... I suppose we could add it as an optional 3rd argument.
Added gwc.output.replace with searchValue, newValue and an optional [use html] argument. The last argument determines if text() or htm() is used as the input value. Output is always added using html()

Re: Text Coloring

Posted: 19 Oct 2013 14:46
by Yanus
.