Parse a BBCode [font=] tag
var apply = document.getElementsByClassName("postmsg"); | |
var sigs = document.getElementsByClassName("postsignature"); | |
var i; | |
for (i = 0; i < sigs.length; i++) { | |
apply[apply.length] = sigs[i]; | |
} | |
var fonts = []; | |
var texts = []; | |
for (i = 0; i < apply.length; i++) { | |
var applyTo = apply[i]; | |
var thishtml = applyTo.innerHTML; | |
var j; | |
for (j = 0; j < thishtml.split("[font=").length-1; j++) { | |
var stuff = thishtml.split("[font=")[j+1].split("]"); | |
fonts[j] = stuff[0]; | |
texts[j] = stuff[1].split("[")[0]; | |
} | |
for (j = 0; j < fonts.length; j++) { | |
fonts[j] = fonts[j].replace(/'|"/g, ""); | |
texts[j] = texts[j].replace(/'|"/g, ""); | |
thishtml = thishtml.replace(/\[font=(.+?)\](.+?)\[\/font\]/, "<span style=\"font-family: '"+fonts[j]+"'\">"+texts[j]+"</span>"); | |
} | |
applyTo.innerHTML = thishtml; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment