html-docx-js
Version:
Converts HTML documents to DOCX in the browser
28 lines (27 loc) • 919 B
JavaScript
var _ = {};
var escapeMap = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
};
var escapeRegexp = new RegExp('[' + Object.keys(escapeMap).join('') + ']', 'g');
_.escape = function(string) {
if (!string) return '';
return String(string).replace(escapeRegexp, function(match) {
return escapeMap[match];
});
};
module.exports = function(obj) {
obj || (obj = {});
var __t, __p = '', __e = _.escape;
with (obj) {
__p += 'MIME-Version: 1.0\nContent-Type: multipart/related;\n type="text/html";\n boundary="----=mhtDocumentPart"\n\n\n------=mhtDocumentPart\nContent-Type: text/html;\n charset="utf-8"\nContent-Transfer-Encoding: quoted-printable\nContent-Location: file:///C:/fake/document.html\n\n' +
((__t = ( htmlSource )) == null ? '' : __t) +
'\n\n' +
((__t = ( contentParts )) == null ? '' : __t) +
'\n\n------=mhtDocumentPart--\n';
}
return __p
}