aboutsummaryrefslogtreecommitdiffstats
path: root/tools/post-markdown-test.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-10-09 21:48:11 -0700
committerAdam Soltys <[email protected]>2026-10-09 21:48:11 -0700
commitfaec1f84ed1e9e8ee78055796a8ebc92936abe9d (patch)
tree4d31820e4b1fd762ca40727711ee1ab365bf201f /tools/post-markdown-test.js
parent75ca3da7f87846f26743d0c27afc90d9f0d19a7c (diff)
downloadcoinosv3-faec1f84ed1e9e8ee78055796a8ebc92936abe9d.tar.gz
coinosv3-faec1f84ed1e9e8ee78055796a8ebc92936abe9d.zip
Posts: inline markdown. **bold** / __bold__, *italic* / _italic_, ***both***, ~~struck~~ and `code` render in a post's plain text — what newsletter bots and Amethyst users type and Amethyst shows; we showed the asterisks. Strict about edges, so snake_case, x__init__y, 2*3*4, "$5 * 2" and a lone star stay as typed, and markers never reach across a link, mention or hashtag. No headings or lists in posts: "#" at a line's start is a hashtag here, and articles render their own headings. tools/post-markdown-test.js
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vps2H27rhbG9ZqseGfMrc3
Diffstat (limited to 'tools/post-markdown-test.js')
-rw-r--r--tools/post-markdown-test.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/tools/post-markdown-test.js b/tools/post-markdown-test.js
new file mode 100644
index 0000000..e4cf27b
--- /dev/null
+++ b/tools/post-markdown-test.js
@@ -0,0 +1,43 @@
+// Posts render the inline markdown people type — **bold**, *italic*,
+// ~~struck~~, `code` — and leave snake_case, 2*3*4 and lone stars alone.
+// Run: bun tools/post-markdown-test.js
+import puppeteer from './puppeteer.js';
+import { finalizeEvent, generateSecretKey } from 'nostr-tools/pure';
+import { buildHtml, buildVerifyWorker } from '../build.js';
+let ok = true;
+const check = (n, c, d = '') => { console.log(` ${c ? '✓' : '✗'} ${n}${d ? ' — ' + d : ''}`); if (!c) ok = false; };
+const sk = generateSecretKey(), now = Math.floor(Date.now() / 1000);
+const TEXT = "📰 **In this week's issue:**\n\nWhen the *servers* go ~~dark~~ away, run `git clone` and keep snake_case_names, 2*3*4 and a lone * star as they are. This is plain English prose for the language check.";
+const note = finalizeEvent({ kind: 1, created_at: now, tags: [], content: TEXT }, sk);
+const profile = finalizeEvent({ kind: 0, created_at: now, tags: [], content: JSON.stringify({ name: 'Newsletter' }) }, sk);
+const html = await buildHtml({ minify: true, pwa: false });
+const worker = await buildVerifyWorker({ minify: true });
+const server = Bun.serve({ port: 0, fetch(req) {
+ const path = new URL(req.url).pathname;
+ if (path === '/api/feed') return Response.json({ version: 1, generatedAt: Date.now(), popUntil: now - 100, notes: [note], profiles: [profile] });
+ if (path === '/verify-worker.js') return new Response(worker, { headers: { 'Content-Type': 'text/javascript' } });
+ return new Response(html, { headers: { 'Content-Type': 'text/html' } });
+} });
+const browser = await puppeteer.launch({ executablePath: '/usr/bin/google-chrome', headless: 'new', args: ['--no-sandbox'] });
+try {
+ const page = await browser.newPage();
+ const errs = [];
+ page.on('pageerror', (e) => errs.push(String(e)));
+ await page.evaluateOnNewDocument(() => {
+ const Real = window.WebSocket;
+ window.WebSocket = function (...a) { const ws = new Real(...a); const send = ws.send.bind(ws); ws.send = (d) => { try { const m = JSON.parse(d); if (m[0] === 'REQ') { setTimeout(() => ws.dispatchEvent(new MessageEvent('message', { data: JSON.stringify(['EOSE', m[1]]) })), 0); return; } } catch {} return send(d); }; return ws; };
+ window.WebSocket.prototype = Real.prototype; Object.assign(window.WebSocket, Real);
+ });
+ await page.goto(server.url.origin + '/feed');
+ await page.waitForFunction(() => document.querySelector('.note-text strong'), { timeout: 15000 }).catch(() => {});
+ const r = await page.evaluate(() => {
+ const t = document.querySelector('.note-text');
+ return t ? { strong: [...t.querySelectorAll('strong')].map((x) => x.textContent), em: [...t.querySelectorAll('em')].map((x) => x.textContent), s: [...t.querySelectorAll('s')].map((x) => x.textContent), code: [...t.querySelectorAll('code')].map((x) => x.textContent), text: t.innerText } : null;
+ });
+ check('**bold** is bold, markers gone', r && r.strong[0] === "In this week's issue:" && !r.text.includes('**'), JSON.stringify(r && r.strong));
+ check('*italic*, ~~struck~~ and `code`', r && r.em[0] === 'servers' && r.s[0] === 'dark' && r.code[0] === 'git clone', JSON.stringify(r && [r.em, r.s, r.code]));
+ check('snake_case, 2*3*4 and a lone star stay as typed', r && r.text.includes('snake_case_names, 2*3*4 and a lone * star'));
+ check('no page errors', errs.length === 0, errs.slice(0, 2).join(' | '));
+} finally { await browser.close(); server.stop(true); }
+console.log(ok ? '\n✅ posts render inline markdown' : '\n❌ failed');
+process.exit(ok ? 0 : 1);