class MDRenderer { constructor() { this.rules = { heading: /^[ \t]{0,3}(#{1,6})[ \t]+(.+?)[ \t]*$/gm, paragraph: /^(?!<|@@MDRENDER_|[ \t]{0,3}(?:#{1,6}[ \t]|[-*+][ \t]|\d{1,9}[.)][ \t])|[ \t]*(?:[-*_][ \t]*){3,}[ \t]*$|[ \t]*={3,}[ \t]*$)(.*\S.*)$/gm, boldItalic: /\*\*\*([^*]+?)\*\*\*/g, boldItalicU: /___([^_]+?)___/g, bold: /\*\*([^*]+?)\*\*/g, boldU: /__([^_]+?)__/g, italic: /\*([^*\n]+?)\*/g, italicU: /(??@[\\\]^_`{|}~])/g, refLink: /\[([^\]\n]+)\]\[([^\]\n]*)\]/g, refShortcut: /\[([^\]\n]+)\](?![\(\[])/g, refImage: /!\[([^\]\n]+)\]\[([^\]\n]*)\]/g, emoji: /:([a-zA-Z0-9_+-]+):/g, }; this.footnotes = new Map(); this.abbreviations = new Map(); this.references = new Map(); this._stash = []; this._nonce = ''; this._headingIds = {}; this.emojis = { 'smile': 'đ', 'laugh': 'đ', 'joy': 'đ', 'wink': 'đ', 'heart': 'â¤ī¸', 'heart_eyes': 'đ', 'thinking': 'đ¤', 'clap': 'đ', 'wave': 'đ', 'eyes': 'đ', 'check': 'â ', 'x': 'â', 'warning': 'â ī¸', 'info': 'âšī¸', 'thumbsup': 'đ', 'thumbsdown': 'đ', 'rocket': 'đ', 'star': 'â', 'fire': 'đĨ', 'sunny': 'âī¸', 'sun': 'âī¸', 'moon': 'đ', 'cloud': 'âī¸', 'coffee': 'â', 'pizza': 'đ', 'cake': 'đ°', 'apple': 'đ', 'tada': 'đ', 'bug': 'đ', 'zap': 'âĄ', }; } render(markdown) { this.footnotes = new Map(); this.abbreviations = new Map(); this.references = new Map(); this._stash = []; this._nonce = Math.random().toString(36).slice(2, 10); this._headingIds = {}; let html = this._render(String(markdown ?? '')); if (this.footnotes.size > 0) { html += this.renderFootnotesSection(); } const tokenRe = new RegExp(`@@MDRENDER_${this._nonce}_(\\d+)@@`, 'g'); const resolve = (s) => s.replace(tokenRe, (m, i) => { const v = this._stash[+i]; return v === undefined ? m : resolve(v); }); html = resolve(html); return `