Skip to content

Commit

Permalink
Add note preview HTML stripping
Browse files Browse the repository at this point in the history
  • Loading branch information
addyosmani committed Oct 27, 2024
1 parent 248e4eb commit 4b19f45
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/NoteList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ interface NoteListProps {
onCreateNote: () => void;
}

const stripHtmlTags = (html: string) => {
const doc = new DOMParser().parseFromString(html, 'text/html');
return doc.body.textContent || '';
};

const NoteList: React.FC<NoteListProps> = ({ notes, selectedNoteId, onSelectNote, onDeleteNote, onCreateNote }) => {
return (
<div className="note-list">
Expand All @@ -37,7 +42,7 @@ const NoteList: React.FC<NoteListProps> = ({ notes, selectedNoteId, onSelectNote
>
<div className="truncate">{note.title}</div>
<div className="text-xs text-gray-500 truncate">
{note.content.slice(0, 50)}{note.content.length > 50 ? '...' : ''}
{stripHtmlTags(note.content).slice(0, 50)}{note.content.length > 50 ? '...' : ''}
</div>
</button>
<button
Expand Down

0 comments on commit 4b19f45

Please sign in to comment.