fix(newsletter): render _underscore italics_ in issue bodies

issueToMarkdown wraps each issue's vibe in _underscores_, but the in-app
markdown renderer only understood *asterisk* emphasis — so every published
archive issue showed LITERAL underscores around its intro line (both in our
reader and here). Added the underscore form to the tokenizer.

Verified on the live issue-5 naddr: the vibe now renders as <em> with no
literal underscores.
This commit is contained in:
SkateSpots 2026-09-27 20:34:31 +07:00
parent 261e4c9115
commit 565fdb9211

View file

@ -29,8 +29,11 @@ function renderMarkdown(md: string) {
const renderInline = (text: string): React.ReactNode[] => { const renderInline = (text: string): React.ReactNode[] => {
const nodes: React.ReactNode[] = []; const nodes: React.ReactNode[] = [];
// Tokenise **bold**, *italic*, and [label](url) / bare http(s) links. // Tokenise **bold**, *italic*, _italic_ (underscore form — issueToMarkdown
const regex = /(\*\*([^*]+)\*\*)|(\*([^*]+)\*)|(\[([^\]]+)\]\((https?:\/\/[^\s)]+)\))|(https?:\/\/[^\s]+)/g; // wraps the vibe in underscores, which used to render as LITERAL underscores
// in this reader), [label](url) and bare http(s) links.
const regex =
/(\*\*([^*]+)\*\*)|(\*([^*]+)\*)|(_([^_]+)_)|(\[([^\]]+)\]\((https?:\/\/[^\s)]+)\))|(https?:\/\/[^\s]+)/g;
let last = 0; let last = 0;
let m: RegExpExecArray | null; let m: RegExpExecArray | null;
let i = 0; let i = 0;
@ -41,15 +44,17 @@ function renderMarkdown(md: string) {
} else if (m[3]) { } else if (m[3]) {
nodes.push(<em key={i++} className="italic">{m[4]}</em>); nodes.push(<em key={i++} className="italic">{m[4]}</em>);
} else if (m[5]) { } else if (m[5]) {
nodes.push(<em key={i++} className="italic">{m[6]}</em>);
} else if (m[7]) {
nodes.push( nodes.push(
<a key={i++} href={m[7]} target="_blank" rel="noopener noreferrer" className="text-[#ccff00] underline underline-offset-2 hover:opacity-80"> <a key={i++} href={m[9]} target="_blank" rel="noopener noreferrer" className="text-[#ccff00] underline underline-offset-2 hover:opacity-80">
{m[6]} {m[8]}
</a>, </a>,
); );
} else if (m[8]) { } else if (m[10]) {
nodes.push( nodes.push(
<a key={i++} href={m[8]} target="_blank" rel="noopener noreferrer" className="text-[#ccff00] underline underline-offset-2 hover:opacity-80 break-all"> <a key={i++} href={m[10]} target="_blank" rel="noopener noreferrer" className="text-[#ccff00] underline underline-offset-2 hover:opacity-80 break-all">
{m[8]} {m[10]}
</a>, </a>,
); );
} }