'use strict'; // ---- A small, safe Markdown renderer for notes: headings, bold, italic, strike, code, links, quotes, bullet and numbered lists, and "- [ ]" tick boxes. // Everything is escaped first, and only http(s) links are made clickable, so a note can never inject a script or a strange link. function ntMd(src) { const inline = t => esc(t) .replace(/`([^`]+)`/g, '$1') .replace(/\*\*([^*]+)\*\*/g, '$1').replace(/(^|[\s(])\*([^*\s][^*]*)\*/g, '$1$2').replace(/~~([^~]+)~~/g, '$1') .replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g, '$1') .replace(/(^|[\s(])(https?:\/\/[^\s<)]+)/g, '$1$2'); const lines = String(src || '').replace(/\r/g, '').split('\n'), out = []; let list = null, code = false, para = []; const endPara = () => { if (para.length) { out.push('

' + para.map(inline).join('
') + '

'); para = []; } }; const endList = () => { if (list) { out.push(``); list = null; } }; lines.forEach((raw, i) => { if (/^```/.test(raw)) { endPara(); endList(); out.push(code ? '' : '
'); code = !code; return; }
    if (code) { out.push(esc(raw) + '\n'); return; }
    let m;
    if ((m = /^(\s*)[-*+] \[( |x|X)\] (.*)$/.exec(raw))) { endPara(); if (list !== 'ul') { endList(); out.push('
'); return out.join(''); } /** The text of a note without the Markdown marks, for the small preview on a card. */ const ntPlain = s => String(s || '').replace(/```/g, '').replace(/^#{1,3} /gm, '').replace(/^\s*[-*+] \[( |x|X)\] /gm, (m, x) => x === ' ' ? '☐ ' : '☑ ').replace(/^\s*[-*+] /gm, '• ').replace(/^> ?/gm, '').replace(/\*\*([^*]+)\*\*/g, '$1').replace(/~~([^~]+)~~/g, '$1').replace(/\[([^\]]+)\]\([^)]+\)/g, '$1').replace(/`([^`]+)`/g, '$1');