partial fix for #798.

It turns out that the missing closing tags was caused by an encoding
exception and misuse of the Encoder API. The exception was due to
the &raquo; entity which isn't supported by the Shift_JIS encoding
which caused the encoder to stop half way while it's converting the
UTF-16 content of the document to Shift_JIS. To fix this, we convert
all characters not supported by the current encoding to html entities.
don't encode the script tag. fix #798.
Merge branch 'issue-798'