Skip to content

Commit c19f2a8

Browse files
AmirMohammad CheraghaliAmirMohammad Cheraghali
authored andcommitted
fix: clean notebook card previews to strip code blocks, tables, and raw markdown
Cards were showing raw content like table pipes (||||) and code block data (python-kernel eyJ...). Added getCleanPreview() that strips fenced code blocks, tables, HTML, markdown syntax, and base64 strings before truncating for display.
1 parent 5d2d80d commit c19f2a8

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

src/components/dashboard/LabNotebook.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,36 @@ export const LabNotebook: React.FC<{ isDrawer?: boolean }> = ({ isDrawer = false
3838

3939
const activeNotebook = notebooks.find(n => n.id === activeId);
4040

41+
// Clean preview: strip markdown artifacts, code blocks, tables, etc.
42+
const getCleanPreview = (content: string): string => {
43+
if (!content) return '';
44+
let text = content;
45+
// Remove fenced code blocks (```...```) including python-kernel blocks
46+
text = text.replace(/```[\s\S]*?```/g, '');
47+
// Remove inline code
48+
text = text.replace(/`[^`]+`/g, '');
49+
// Remove table rows (lines with pipes)
50+
text = text.replace(/^\|.*\|$/gm, '');
51+
// Remove table separator rows
52+
text = text.replace(/^[\s|:_-]+$/gm, '');
53+
// Remove HTML tags
54+
text = text.replace(/<[^>]+>/g, '');
55+
// Remove markdown headers
56+
text = text.replace(/^#{1,6}\s+/gm, '');
57+
// Remove markdown bold/italic
58+
text = text.replace(/\*{1,3}([^*]+)\*{1,3}/g, '$1');
59+
text = text.replace(/_{1,3}([^_]+)_{1,3}/g, '$1');
60+
// Remove markdown links [text](url)
61+
text = text.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1');
62+
// Remove markdown images ![alt](url)
63+
text = text.replace(/!\[([^\]]*)\]\([^)]*\)/g, '');
64+
// Remove base64/encoded strings (long runs of alphanumeric+special chars)
65+
text = text.replace(/[A-Za-z0-9+/=]{40,}/g, '');
66+
// Collapse whitespace
67+
text = text.replace(/\s+/g, ' ').trim();
68+
return text.substring(0, 80) || '';
69+
};
70+
4171
useEffect(() => {
4272
if (!user) return;
4373
const fetchNotebooks = async () => {
@@ -312,7 +342,7 @@ export const LabNotebook: React.FC<{ isDrawer?: boolean }> = ({ isDrawer = false
312342
</button>
313343
</div>
314344
<p className="text-xs opacity-60 truncate">
315-
{entry.content.substring(0, 60) || t.emptyEntry}
345+
{getCleanPreview(entry.content) || t.emptyEntry}
316346
</p>
317347
<p className="text-[10px] opacity-40 mt-2 font-mono">
318348
{new Date(entry.updated_at).toLocaleDateString()}

0 commit comments

Comments
 (0)