// EPUB pieces shared by fetch-novel.js (new books) and update-novels.js (appends). import { load } from 'cheerio'; import { stripPromo } from './clean-chapter.js'; export const esc = s => String(s ?? '').replace( /[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[c], ); // Chapter HTML is tag soup; re-serialise it as well-formed XHTML without // scripts, remote resources (an EPUB must be self-contained) or promo lines. export const toXhtml = html => { const $ = load(html, null, false); $('script, style, iframe, link, meta, img, video, audio, source').remove(); stripPromo($); return $.xml(); }; export const page = (title, body) => ` ${esc(title)} ${body} `; export const chapterPage = (title, body) => page(title, `

${esc(title)}

\n${body}`);