import crypto from 'crypto' import scopeCss from '@patarapolw/scope-css' import cheerio from 'cheerio' import ejs from 'ejs' import jieba from 'nodejieba' import showdown from 'showdown' export class MakeHTML { $ = cheerio.load('') mdConverter = new showdown.Converter({ noHeaderId: true, parseImgDimensions: true, simplifiedAutoLink: true, // literalMidWordUnderscores: true, strikethrough: true, tables: true, tasklists: true, // simpleLineBreaks: true, openLinksInNewWindow: true, backslashEscapesHTMLTags: true, emoji: true, underline: true, metadata: true, }) constructor() { /** * ! For some reasons default underscore italic fails to render... */ this.mdConverter.addExtension( { type: 'lang', regex: /([^\\])_{1}(.*?[^\\])_{1}/g, replace: '$1$2', }, 'underscore-italic' ) /** * ! This is the only way to preserve syntax highlighting, while output multiline strings correctly */ this.mdConverter.addExtension( { type: 'lang', regex: /(^|\n)```html parsed([^]+)\n```\n/g, replace: (_: string, p1: string, p2: string) => { return ( p1 + ejs.render(p2, { rmWhitespace: true, beautify: false, }) ) }, }, 'html-parsed' ) } async parse( filename: string ): Promise<{ $: cheerio.Cheerio html(): string clean(): string }> { const id = 'md-' + crypto .createHash('sha256') .update(filename) .digest() .toString('hex') .substr(0, 8) const $div = this.$(`