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.
ircStylize("^Bbolded part ^0 not bolded part");// => "<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 = require("irc-style-parser");var Handlebars = require("Handlebars");var jQuery = require("jquery");// Set template of ircStylize if desired called with {style: '', text: msg}ircStylize.template = Handlebars.compile("<span class='{{style}}'>{{{text}}}</span>");// Parse a message to HTML or whatever your template outputsvar $parsed = jQuery(ircStylize(msg));
Todo
[ ] Make it easier to add/change a colour
[ ] Remove ES5 dependency?