What about?

text = text.replace(/]]>/g, "]]><![CDATA[>");