IRC Style and Colour Parser
IRC Style parsing is ridiculously tricky as I found writing this for qwebirc. Besides the numerous edge cases, the spec is semi-ambigous (e.g. will the second x have a background in the string "^C1,2x^C3x"
?). This implementation follows the defacto implementations of mibbit and xchat -- however if you want options to handle particular cases cases differently make an issue.
This implementation should work consistently in near any environment (IE6 ) [with an es5 array method shim] and is well tested
Handles:
- Unlimitted nesting
- Colours (
^C
): Default outputs as
message
- Underlines (
^u
): Default outputs as
message
- Italics (
^i
): Default outputs as
message
- Bold (
^B
): Default outputs as
message
- Normal (
^o
): Default outputs as
message
- Escaping (
^0
): E.g.
;// => "<span class="irc-bold">bolded part </span> not bolded part"
Note: the ^C
/^u
/etc isn't used internally - we only replace the UTF8 versions of the string see here
Usage
var ircStylize = ;var Handlebars = ;var jQuery = ; // Set template of ircStylize if desired called with {style: '', text: msg}ircStylizetemplate = Handlebars; // Parse a message to HTML or whatever your template outputsvar $parsed = ;
Todo [ ] Make it easier to add/change a colour [ ] Remove ES5 dependency?