chore: polish

This commit is contained in:
2024-03-27 08:36:34 +07:00
parent aa23e39334
commit d3fa59d2b1
5 changed files with 23 additions and 6 deletions

View File

@@ -18,14 +18,22 @@ import { VideoPreview } from "./preview/video";
import { ImagePreview } from "./preview/image";
import reactStringReplace from "react-string-replace";
export function NoteContent({ className }: { className?: string }) {
export function NoteContent({
compact = true,
className,
}: {
compact?: boolean;
className?: string;
}) {
const event = useNoteContext();
const content = useMemo(() => {
const text = event.content.trim();
const words = text.split(/( |\n)/);
// @ts-ignore, kaboom !!!
let parsedContent: ReactNode[] = text;
let parsedContent: ReactNode[] = compact
? text.replace(/\n\s*\n/g, "\n")
: text;
const hashtags = words.filter((word) => word.startsWith("#"));
const events = words.filter((word) =>
@@ -112,6 +120,12 @@ export function NoteContent({ className }: { className?: string }) {
},
);
if (compact) {
parsedContent = reactStringReplace(parsedContent, /\n|\r/g, () => (
<div key={nanoid()} className="h-1.5" />
));
}
return parsedContent;
} catch (e) {
return text;