feat(web): project detail views — missions, tasks, PRD viewer (#122) (#140)
Some checks failed
ci/woodpecker/push/ci Pipeline failed

Co-authored-by: Jason Woltje <jason@diversecanvas.com>
Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #140.
This commit is contained in:
2026-03-15 18:28:14 +00:00
committed by jason.woltje
parent d42cd68ea4
commit f208f72dc0
7 changed files with 883 additions and 3 deletions

View File

@@ -0,0 +1,99 @@
'use client';
interface PrdViewerProps {
content: string;
}
/**
* Lightweight markdown-to-HTML renderer for PRD content.
* Supports headings, bold, italic, inline code, code blocks, and lists.
* No external dependency — keeps bundle size minimal.
*/
function renderMarkdown(md: string): string {
let html = md
// Escape HTML entities first to prevent XSS
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
// Code blocks (must run before inline code)
html = html.replace(/```[\w]*\n?([\s\S]*?)```/g, (_match, code: string) => {
return `<pre class="overflow-x-auto rounded-lg bg-surface-elevated p-4 my-4"><code class="text-xs text-text-secondary whitespace-pre">${code.trim()}</code></pre>`;
});
// Headings
html = html.replace(
/^#### (.+)$/gm,
'<h4 class="text-sm font-semibold text-text-primary mt-4 mb-1">$1</h4>',
);
html = html.replace(
/^### (.+)$/gm,
'<h3 class="text-base font-semibold text-text-primary mt-6 mb-2">$1</h3>',
);
html = html.replace(
/^## (.+)$/gm,
'<h2 class="text-lg font-semibold text-text-primary mt-8 mb-3">$1</h2>',
);
html = html.replace(
/^# (.+)$/gm,
'<h1 class="text-xl font-bold text-text-primary mt-8 mb-4">$1</h1>',
);
// Horizontal rule
html = html.replace(/^---$/gm, '<hr class="my-6 border-surface-border" />');
// Unordered list items
html = html.replace(
/^[-*] (.+)$/gm,
'<li class="ml-4 text-sm text-text-secondary list-disc">$1</li>',
);
// Ordered list items
html = html.replace(
/^\d+\. (.+)$/gm,
'<li class="ml-4 text-sm text-text-secondary list-decimal">$1</li>',
);
// Bold + italic
html = html.replace(/\*\*\*(.+?)\*\*\*/g, '<strong><em>$1</em></strong>');
// Bold
html = html.replace(
/\*\*(.+?)\*\*/g,
'<strong class="font-semibold text-text-primary">$1</strong>',
);
// Italic
html = html.replace(/\*(.+?)\*/g, '<em class="italic text-text-secondary">$1</em>');
// Inline code
html = html.replace(
/`([^`]+)`/g,
'<code class="rounded bg-surface-elevated px-1 py-0.5 text-xs text-text-secondary">$1</code>',
);
// Paragraphs — wrap lines that aren't already wrapped in a block element
const lines = html.split('\n');
const result: string[] = [];
for (const line of lines) {
const trimmed = line.trim();
if (trimmed === '') {
result.push('');
} else if (
trimmed.startsWith('<h') ||
trimmed.startsWith('<pre') ||
trimmed.startsWith('<li') ||
trimmed.startsWith('<hr')
) {
result.push(trimmed);
} else {
result.push(`<p class="text-sm text-text-secondary leading-relaxed my-2">${trimmed}</p>`);
}
}
return result.join('\n');
}
export function PrdViewer({ content }: PrdViewerProps): React.ReactElement {
const html = renderMarkdown(content);
return <div className="prose prose-sm max-w-none" dangerouslySetInnerHTML={{ __html: html }} />;
}