fix #1095 by special casing empty HtmlJavascript

Without this an empty <script src""></script> can be added to the
output of the templates. So to avoid this problem we get the text and
then only use it if there is something other than whitespace.

Added a test for this previously untested functionality.