UNPKG

epub-maker2

Version:
60 lines 1.84 kB
"use strict"; /** * Created by user on 2017/12/15/015. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.htmlminify = exports.formatHTML = void 0; const js_beautify_1 = require("js-beautify"); const html_minifier_1 = require("html-minifier"); function formatHTML(htmlstr, skipFormatting) { if (skipFormatting || typeof js_beautify_1.html_beautify === 'undefined') { return htmlstr; } return htmlminify(htmlstr) //.replace(/<item id="" href="image\/" media-type="" \/>/ig, '') .replace(/^\n+|\n+$/, '\n'); } exports.formatHTML = formatHTML; function htmlminify(html, options = {}) { options = Object.assign({ collapseWhitespace: true, preserveLineBreaks: true, conservativeCollapse: true, caseSensitive: true, keepClosingSlash: true, ignoreCustomFragments: [ /\<\/[ \t]*meta\>/i, ], }, options); try { let ret = (0, html_minifier_1.minify)(html, options); return ret; } catch (e) { try { let ret = (0, js_beautify_1.html_beautify)(html, { end_with_newline: true, indent_char: '', indent_inner_html: false, indent_size: 0, // @ts-ignore indent_level: 0, max_preserve_newlines: 1, preserve_newlines: true, wrap_line_length: 0, unformatted: [], // @ts-ignore selector_separator_newline: false, newline_between_rules: true }); return ret; } catch (e) { console.error(e); } } return html; } exports.htmlminify = htmlminify; exports.default = exports; //# sourceMappingURL=index.js.map