BUG: Fix for #1487

The parser could sometimes generate invalid code if the
source-file-comments were enabled, this moves the comments outside the
html-tag to circumvent these problems, update test as well.
Merge pull request #1726 from s-m/1487-fix-template-comments

BUG: Fix invalid code with source-file-comments, fixes #1487