properly escape values in the js head

had another case similar to #4944 where newlines were breaking js. properly escaping them now.