0

I'm trying to setup a text modifier for my server, where if you type something like hello ~world~ it would italic the 'world' part. I want to do this in Javascript, but I have no idea about how I would go about doing this.

Basically here's how scripting looks for where I'm running my server off of. This is also what I basically have done now, for this text modify script.

beforeChatMessage: function(src, message, chan) {
var user = sys.name(src);
var usercolor = sys.color(src)
if (message.toLowerCase().match("~")){
var italicmessage = message.replace(message, "<i>");
sys.sendHtmlAll("<font color="+usercolor+"><timestamp/> "+user+": "+italicmessage+"", channel);
return;
}

This obviously doesn't work, so, I'm guessing the correct way to would be to use substrings? Any help would be great.

3
  • can't you set up something like CKEditor or TinyMCE? Commented Jan 5, 2015 at 3:09
  • No haha, my server is basically running off of a game, where you can host your own servers. Each server can be setup with scripts. Commented Jan 5, 2015 at 3:14
  • type into where? a chatroom type thing? do you want it to appear italicised after hitting enter and having the text appear in the chatroom? Commented Jan 5, 2015 at 3:20

2 Answers 2

1

You can do something like that with the contenteditable="true" attribute:

<div id="demo" contenteditable="true">Hello world!</div>

<script>
    demo.innerHTML = demo.innerHTML.replace("world", "<span style='font-style: italic'>world</span>");
</script>

Refer to this fiddle to see it working.

Sign up to request clarification or add additional context in comments.

1 Comment

This wouldn't work on what I'm running my server off of, basically its off a game application and they have their own variation of Javascript. Check my OP, I edited it with what I basically have done and what I mean so you can get more clear.
0

I found a way to actually do this, I tested and it seems to be working. Just using regex seems to work. Example;

bold: /[b](.*?)[/b]/gi,

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.