Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(web): preserve comment markdown spacing

Tin7bf0d8313f46
diff --git a/apps/web/src/components/activity/comment-editor.tsx b/apps/web/src/components/activity/comment-editor.tsx
index d4d22b316..253c13765 100644
--- a/apps/web/src/components/activity/comment-editor.tsx
+++ b/apps/web/src/components/activity/comment-editor.tsx
@@ -69,6 +69,7 @@ import {
isYouTubeUrl,
normalizeUrl,
} from "@/lib/editor-url-utils";
+import { normalizeCommentMarkdown } from "@/lib/normalize-comment-markdown";
import { getSharedShikiHighlighter } from "@/lib/shiki-highlighter";
import { toast } from "@/lib/toast";
import { uploadTaskImage } from "@/lib/upload-task-image";
@@ -148,15 +149,6 @@ const COMMENT_SHIKI_LANGUAGE_ALIASES: Record<string, string> = {
plaintext: "text",
};
-function normalizeMarkdown(markdown: string) {
- return markdown
- .replace(/\r\n/g, "\n")
- .replace(/&nbsp;/g, " ")
- .replace(/\u00A0/g, " ")
- .replace(/\n{3,}/g, "\n\n")
- .replace(/\n{2,}$/g, "\n");
-}
-
type EmbedComposerState = {
mode: "choice" | "input";
url: string;
@@ -208,7 +200,7 @@ export default function CommentEditor({
const dragDepthRef = useRef(0);
const isSyncingRef = useRef(false);
const hasHydratedRef = useRef(false);
- const latestValueRef = useRef(normalizeMarkdown(value || ""));
+ const latestValueRef = useRef(normalizeCommentMarkdown(value || ""));
const lastEditorRef = useRef<Editor | null>(null);
const taskIdRef = useRef(taskId);
const ensureTaskIdRef = useRef(ensureTaskId);
@@ -885,7 +877,7 @@ export default function CommentEditor({
},
onUpdate: ({ editor: activeEditor }) => {
if (readOnly || disabled || !onChange || isSyncingRef.current) return;
- const markdown = normalizeMarkdown(activeEditor.getMarkdown());
+ const markdown = normalizeCommentMarkdown(activeEditor.getMarkdown());
latestValueRef.current = markdown;
onChange(markdown);
},
@@ -1035,7 +1027,7 @@ export default function CommentEditor({
lastEditorRef.current = editor;
}
- const incoming = normalizeMarkdown(value || "");
+ const incoming = normalizeCommentMarkdown(value || "");
if (!hasHydratedRef.current) {
isSyncingRef.current = true;
latestValueRef.current = incoming;
diff --git a/apps/web/src/index.css b/apps/web/src/index.css
index d4be617e3..1fbbb3faa 100644
--- a/apps/web/src/index.css
+++ b/apps/web/src/index.css
@@ -1104,6 +1104,11 @@ input:-webkit-autofill:active {
margin: 0;
}
+ .kaneo-comment-editor-prose > p + p,
+ .kaneo-comment-editor-prose > :is(ul, ol) + p {
+ margin-top: 0.75rem;
+ }
+
.kaneo-comment-editor-prose h1,
.kaneo-comment-editor-prose h2,
.kaneo-comment-editor-prose h3 {
diff --git a/apps/web/src/lib/normalize-comment-markdown.test.ts b/apps/web/src/lib/normalize-comment-markdown.test.ts
new file mode 100644
index 000000000..f33153afd
--- /dev/null
+++ b/apps/web/src/lib/normalize-comment-markdown.test.ts
@@ -0,0 +1,24 @@
+import { describe, expect, it } from "vitest";
+import { normalizeCommentMarkdown } from "./normalize-comment-markdown";
+
+describe("normalizeCommentMarkdown", () => {
+ it("preserves explicit blank paragraphs", () => {
+ expect(
+ normalizeCommentMarkdown(
+ "This is a test comment\n\n\n\nThis is another paragraph",
+ ),
+ ).toBe("This is a test comment\n\n\n\nThis is another paragraph");
+ });
+
+ it("preserves the blank paragraph that separates a list from later text", () => {
+ expect(normalizeCommentMarkdown("- Item\n\n\n\nNot a list item")).toBe(
+ "- Item\n\n\n\nNot a list item",
+ );
+ });
+
+ it("normalizes platform newlines and non-breaking spaces", () => {
+ expect(normalizeCommentMarkdown("First\r\nSecond&nbsp;\u00A0line")).toBe(
+ "First\nSecond line",
+ );
+ });
+});
diff --git a/apps/web/src/lib/normalize-comment-markdown.ts b/apps/web/src/lib/normalize-comment-markdown.ts
new file mode 100644
index 000000000..57d9531a8
--- /dev/null
+++ b/apps/web/src/lib/normalize-comment-markdown.ts
@@ -0,0 +1,6 @@
+export function normalizeCommentMarkdown(markdown: string) {
+ return markdown
+ .replace(/\r\n/g, "\n")
+ .replace(/&nbsp;/g, " ")
+ .replace(/\u00A0/g, " ");
+}