diff --git a/package.json b/package.json index 3ff0805..8d5f59e 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "adm-zip": "^0.4.7", "ansi-to-html": "^0.4.2", "body-parser": "^1.15.2", + "cheerio": "^1.0.0-rc.1", "cookie-parser": "^1.4.3", "cssfilter": "0.0.10", "download": "^5.0.3", diff --git a/utility.js b/utility.js index f091fdc..45f8a29 100644 --- a/utility.js +++ b/utility.js @@ -103,10 +103,24 @@ module.exports = { return xss.process(s); }; let replaceUI = s => { - if (noReplaceUI) return s; - return s.split('
').join('
').split('
').join('
') - .split('').join('
') - .split('
').join('
').split('
').join(''); + if (noReplaceUI) return s; + + s = s.split('
').join('
').split('
').join('
') + .split('
').join('
') + .split('
').join('
').split('
').join(''); + + let cheerio = require('cheerio'); + let $ = cheerio.load(s); + + let a = $('img:only-child'); + for (let img of Array.from(a)) { + if (!img.prev && !img.next) { + $(img).css('display', 'block'); + $(img).css('margin', '0 auto'); + } + } + + return $.html(); }; return new Promise((resolve, reject) => { if (!keys) {