I made a fairly simple template engine (if I could call it that). Basically my server returns something like
string "This text should be [color:red;font-weight:bold; red and bold]"
Then on the client side I have my parser, for HTML in this case
function parse(str){
return str.replace(/\[(.+?) (.+?)\]/g,'<span style="$1">$2</span>');
}
I was wondering, however, do HTML tags make a difference? If I were to use font
instead of span
, would I win/lose anything?
P.S.: I am aware that this regex may pick up something that wasn't meant to be parsed, but my application doesn't use these braces in texts it returns, so it is alright.