Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
chore: polish markdown rendering rhythm and heading scale
boojackcfb16a8ced9f
diff --git a/web/src/components/MemoContent/CodeBlock.tsx b/web/src/components/MemoContent/CodeBlock.tsxindex 4cf92e563..66a6c37ea 100644--- a/web/src/components/MemoContent/CodeBlock.tsx+++ b/web/src/components/MemoContent/CodeBlock.tsx@@ -114,7 +114,7 @@ const HighlightedCodeBlock = ({ codeContent, language }: HighlightedCodeBlockPro};return (- <pre className="relative my-2 rounded-lg border border-border bg-muted/20 overflow-hidden">+ <pre className="relative my-0 mb-2 rounded-lg border border-border bg-muted/20 overflow-hidden">{/* Header with language label and copy button */}<div className="flex items-center justify-between px-2 py-1 border-b border-border bg-muted/30"><span className="text-xs text-foreground select-none">{language || "text"}</span>diff --git a/web/src/components/MemoContent/MermaidBlock.tsx b/web/src/components/MemoContent/MermaidBlock.tsxindex 340754a1e..993e6b06b 100644--- a/web/src/components/MemoContent/MermaidBlock.tsx+++ b/web/src/components/MemoContent/MermaidBlock.tsx@@ -101,7 +101,7 @@ export const MermaidBlock = ({ children, className }: MermaidBlockProps) => {return (<div- className={cn("mermaid-diagram w-full flex justify-center items-center my-2 overflow-x-auto", className)}+ className={cn("mermaid-diagram w-full flex justify-center items-center my-0 mb-2 overflow-x-auto", className)}dangerouslySetInnerHTML={{ __html: svg }}/>);diff --git a/web/src/components/MemoContent/Table.tsx b/web/src/components/MemoContent/Table.tsxindex 402ef3216..b079e44a2 100644--- a/web/src/components/MemoContent/Table.tsx+++ b/web/src/components/MemoContent/Table.tsx@@ -8,7 +8,7 @@ interface TableProps extends React.HTMLAttributes<HTMLTableElement>, ReactMarkdoexport const Table = ({ children, className, node: _node, ...props }: TableProps) => {return (- <div className="my-2 w-full overflow-x-auto rounded-lg border border-border bg-muted/20">+ <div className="my-0 mb-2 w-full overflow-x-auto rounded-lg border border-border bg-muted/20"><table className={cn("w-full border-collapse text-sm", className)} {...props}>{children}</table>diff --git a/web/src/components/MemoContent/index.tsx b/web/src/components/MemoContent/index.tsxindex d914b496d..ec09a76ef 100644--- a/web/src/components/MemoContent/index.tsx+++ b/web/src/components/MemoContent/index.tsx@@ -25,7 +25,7 @@ const MemoContent = (props: MemoContentProps) => {data-memo-name={props.memoName}className={cn("relative w-full max-w-full wrap-break-word text-base leading-6",- "[&>*:last-child]:mb-0",+ "[&>*:first-child]:mt-0 [&>*:last-child]:mb-0","[&_.katex-display]:max-w-full","[&_.katex-display]:overflow-x-auto","[&_.katex-display]:overflow-y-hidden",diff --git a/web/src/components/MemoContent/markdown/Image.tsx b/web/src/components/MemoContent/markdown/Image.tsxindex 9e84e6e75..6c896bdad 100644--- a/web/src/components/MemoContent/markdown/Image.tsx+++ b/web/src/components/MemoContent/markdown/Image.tsx@@ -1,3 +1,4 @@+import { markdownStyles } from "@/lib/markdownStyles";import { cn } from "@/lib/utils";import type { ReactMarkdownProps } from "./types";@@ -10,7 +11,7 @@ interface ImageProps extends React.ImgHTMLAttributes<HTMLImageElement>, ReactMarexport const Image = ({ className, alt, node: _node, height, width, style, ...props }: ImageProps) => {return (<img- className={cn("max-w-full my-2", !height && "h-auto", className)}+ className={cn(markdownStyles.image, !height && "h-auto", className)}alt={alt}style={{ height: height ? `${height}px` : undefined, width: width ? `${width}px` : undefined, ...style }}{...props}diff --git a/web/src/components/MemoContent/markdown/List.tsx b/web/src/components/MemoContent/markdown/List.tsxindex 6daa0db11..3115dbf15 100644--- a/web/src/components/MemoContent/markdown/List.tsx+++ b/web/src/components/MemoContent/markdown/List.tsx@@ -73,9 +73,7 @@ interface ListProps extends React.HTMLAttributes<HTMLUListElement | HTMLOListEleexport const List = ({ ordered, children, className, node: _node, ...domProps }: ListProps) => {const Component = ordered ? "ol" : "ul";const isTaskList = className?.includes(TASK_LIST_CLASS);- // Task list indentation is handled by task item grid columns; regular lists- // use the shared token (padding + list style).- const listClass = isTaskList ? "my-0 mb-2 list-outside list-none" : ordered ? markdownStyles.orderedList : markdownStyles.bulletList;+ const listClass = isTaskList ? markdownStyles.taskList : ordered ? markdownStyles.orderedList : markdownStyles.bulletList;return (<Component className={cn(listClass, className)} {...domProps}>diff --git a/web/src/components/MemoEditor/Editor/editor.css b/web/src/components/MemoEditor/Editor/editor.cssindex 4129d3882..9992f44b7 100644--- a/web/src/components/MemoEditor/Editor/editor.css+++ b/web/src/components/MemoEditor/Editor/editor.css@@ -68,31 +68,13 @@}& .cm-md-quote {color: var(--muted-foreground);- font-style: italic;}& .cm-md-mark {color: var(--muted-foreground);}- /* Heading lines (require a space after the hashes; headingDecorations.ts). */- & .cm-md-h1 {- font-size: 1.5em;- font-weight: 600;- line-height: 1.3;- }- & .cm-md-h2 {- font-size: 1.3em;- font-weight: 600;- }- & .cm-md-h3 {- font-size: 1.15em;- font-weight: 600;- }- & .cm-md-h4,- & .cm-md-h5,- & .cm-md-h6 {- font-weight: 600;- }+ /* Heading lines get their type (size / weight) from headingTypeClass in+ lib/markdownStyles.ts, shared with the read-only view; headingDecorations.ts. *//* #tag / @mention decorations. */& .cm-memo-tag,diff --git a/web/src/components/MemoEditor/Editor/headingDecorations.ts b/web/src/components/MemoEditor/Editor/headingDecorations.tsindex 1af75b359..921236b02 100644--- a/web/src/components/MemoEditor/Editor/headingDecorations.ts+++ b/web/src/components/MemoEditor/Editor/headingDecorations.ts@@ -1,9 +1,14 @@import { RangeSetBuilder } from "@codemirror/state";import { Decoration, type DecorationSet, EditorView } from "@codemirror/view";+import { type HeadingLevel, headingTypeClass } from "@/lib/markdownStyles";import { HEADING_LINE } from "./formatting";import { viewportDecorations } from "./viewportDecorations";-const lineDecorations = [1, 2, 3, 4, 5, 6].map((level) => Decoration.line({ class: `cm-md-h${level}` }));+// Heading type comes from the same token as the read-only view, so a heading+// keeps its size and weight when the memo is saved.+const lineDecorations = ([1, 2, 3, 4, 5, 6] as const).map((level: HeadingLevel) =>+ Decoration.line({ class: `cm-md-h${level} ${headingTypeClass(level)}` }),+);function build(view: EditorView): DecorationSet {const builder = new RangeSetBuilder<Decoration>();diff --git a/web/src/lib/markdownStyles.ts b/web/src/lib/markdownStyles.tsindex fa6dc6e93..ffe56aa78 100644--- a/web/src/lib/markdownStyles.ts+++ b/web/src/lib/markdownStyles.ts@@ -2,31 +2,46 @@ import { cn } from "@/lib/utils";export type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;-/** Per-level heading classes (size / weight / border), matching MemoContent. */-const headingLevelClasses: Record<HeadingLevel, string> = {- 1: "text-3xl font-bold border-b border-border pb-2",- 2: "text-2xl font-semibold border-b border-border pb-1.5",- 3: "text-xl font-semibold",- 4: "text-lg font-semibold",- 5: "text-base font-semibold",- 6: "text-base font-medium text-muted-foreground",+/**+ * Per-level heading type (size / line height / weight / color), shared by the+ * read-only memo view and the editor's heading-line decorations so a heading+ * looks the same while editing and after saving. The scale stays close to the+ * 16px body: headings organize a note, they are not page titles.+ */+const headingTypeClasses: Record<HeadingLevel, string> = {+ 1: "text-2xl/8 font-semibold",+ 2: "text-xl/7 font-semibold",+ 3: "text-lg/6.5 font-semibold",+ 4: "text-base/6 font-semibold",+ 5: "text-base/6 font-semibold",+ 6: "text-base/6 font-semibold text-muted-foreground",};-/** Shared base classes applied to every heading level. */-const headingBaseClasses = "mt-3 mb-2 leading-tight";+/**+ * Read-only view spacing: more room above than below so a heading binds to the+ * content it introduces; no top margin when it opens its container.+ */+const headingSpacingClasses: Record<HeadingLevel, string> = {+ 1: "mt-5 mb-2 first:mt-0",+ 2: "mt-5 mb-2 first:mt-0",+ 3: "mt-5 mb-1.5 first:mt-0",+ 4: "mt-4 mb-1 first:mt-0",+ 5: "mt-4 mb-1 first:mt-0",+ 6: "mt-4 mb-1 first:mt-0",+};/**- * Complete heading class per level, precomputed once at module load (base +- * per-level). headingClass is a hot path — MemoContent renders it per heading- * on every content render — so the cn() merge happens here, not per call.+ * Complete heading class per level, precomputed once at module load (spacing ++ * type). headingClass is a hot path — MemoContent renders it per heading on+ * every content render — so the cn() merge happens here, not per call.*/const headingClasses: Record<HeadingLevel, string> = {- 1: cn(headingBaseClasses, headingLevelClasses[1]),- 2: cn(headingBaseClasses, headingLevelClasses[2]),- 3: cn(headingBaseClasses, headingLevelClasses[3]),- 4: cn(headingBaseClasses, headingLevelClasses[4]),- 5: cn(headingBaseClasses, headingLevelClasses[5]),- 6: cn(headingBaseClasses, headingLevelClasses[6]),+ 1: cn(headingSpacingClasses[1], headingTypeClasses[1]),+ 2: cn(headingSpacingClasses[2], headingTypeClasses[2]),+ 3: cn(headingSpacingClasses[3], headingTypeClasses[3]),+ 4: cn(headingSpacingClasses[4], headingTypeClasses[4]),+ 5: cn(headingSpacingClasses[5], headingTypeClasses[5]),+ 6: cn(headingSpacingClasses[6], headingTypeClasses[6]),};/**@@ -34,34 +49,50 @@ const headingClasses: Record<HeadingLevel, string> = {* by the read-only memo view (MemoContent). Each value is a complete, standalone* Tailwind class string so it can be dropped onto a DOM element as-is (MemoContent* merges them with `cn`). The editor does not use these — it styles its raw- * markdown source via CodeMirror decorations in `MemoEditor/Editor/theme.ts`.+ * markdown source via CodeMirror decorations in `MemoEditor/Editor/theme.ts`+ * (headings excepted: see `headingTypeClass`).+ *+ * Block rhythm: every block is `my-0 mb-2` (8px between blocks, none above the+ * first), and MemoContent trims the last block's margin. Headings and the+ * horizontal rule are the only blocks with their own vertical spacing; images+ * are inline content and keep a small margin of their own.** These are static string literals so Tailwind's JIT scanner detects them.*/export const markdownStyles = {paragraph: "my-0 mb-2 leading-6",- blockquote: "my-0 mb-2 border-s-4 border-primary/30 ps-3 text-muted-foreground italic",+ // No italic: synthesized obliques render poorly for CJK text.+ blockquote: "my-0 mb-2 border-s-3 border-muted-foreground/25 ps-3 text-muted-foreground",// Direct-child selectors keep each nested disclosure's indicator independent.details: "my-0 mb-2 min-w-0 ps-5 [&[open]>summary]:mb-1 [&[open]>summary>svg]:rotate-90 [&>*:last-child]:mb-0",summary:"relative -ms-5 block cursor-pointer list-none rounded-sm ps-5 pe-1 font-normal leading-6 [overflow-wrap:anywhere] transition-colors hover:bg-muted/50 focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring motion-reduce:transition-none [&::-webkit-details-marker]:hidden",disclosureIcon:"pointer-events-none absolute start-0.5 top-1.25 size-3.5 text-muted-foreground transition-transform duration-150 motion-reduce:transition-none rtl:rotate-180",- bulletList: "my-0 mb-2 list-outside ps-6 list-disc",- orderedList: "my-0 mb-2 list-outside ps-6 list-decimal",- listItem: "mt-0.5 leading-6",+ bulletList: "my-0 mb-2 list-outside ps-6 list-disc marker:text-muted-foreground",+ orderedList: "my-0 mb-2 list-outside ps-6 list-decimal marker:text-muted-foreground",+ // Task list indentation comes from the task item grid columns, not padding.+ taskList: "my-0 mb-2 list-outside list-none",+ // Trimming the last child keeps nested lists and loose-item paragraphs from+ // adding a gap before the next sibling item.+ listItem: "mt-0.5 leading-6 [&>*:last-child]:mb-0",// Shared by the read-only task item (MemoContent/markdown/List.tsx) and the// editor so the checkbox + text grid stays identical in both.taskListItem: "mt-0.5 min-w-0 leading-6 list-none grid grid-cols-[auto_minmax(0,1fr)] items-start gap-x-2 [&>[data-slot=checkbox]]:mt-1",taskItemContent: "min-w-0 [overflow-wrap:anywhere] [&>*:last-child]:mb-0",- inlineCode: "font-mono text-sm bg-muted px-1 py-0.5 rounded-md",+ // Relative size so code inside headings scales with the heading.+ inlineCode: "font-mono text-[0.875em] bg-muted px-1 py-0.5 rounded-md",link: "text-primary underline decoration-primary/50 underline-offset-2 transition-colors hover:decoration-primary",- horizontalRule: "my-2 h-0 border-0 border-b border-border",+ horizontalRule: "my-4 h-0 border-0 border-b border-border",+ image: "max-w-full my-2 rounded-lg",} as const;-/** Complete heading class for a given level (shared base + per-level classes). */+/** Complete heading class for a given level (spacing + type). */export const headingClass = (level: HeadingLevel): string => headingClasses[level];+/** Heading type alone (no spacing), for the editor's heading-line decorations. */+export const headingTypeClass = (level: HeadingLevel): string => headingTypeClasses[level];+/*** Tag pill styling for the read-only memo view (MemoContent/Tag.tsx). Split into* two tokens so the viewer can swap `defaultColor` for an inline custom color.diff --git a/web/tests/memo-content-list.test.tsx b/web/tests/memo-content-list.test.tsxindex 86d6fdc77..84a0f167a 100644--- a/web/tests/memo-content-list.test.tsx+++ b/web/tests/memo-content-list.test.tsx@@ -4,8 +4,12 @@ import remarkGfm from "remark-gfm";import { describe, expect, it } from "vitest";import { TASK_LIST_CLASS, TASK_LIST_ITEM_CLASS } from "@/components/MemoContent/constants";import { List, ListItem } from "@/components/MemoContent/markdown";+import { markdownStyles } from "@/lib/markdownStyles";import { remarkSplitMixedTaskLists } from "@/utils/remark-plugins/remark-split-mixed-task-lists";+// renderToStaticMarkup escapes `&` and `>` inside attribute values.+const listItemClass = markdownStyles.listItem.replaceAll("&", "&").replaceAll(">", ">");+const renderListContent = (content: string): string =>renderToStaticMarkup(<ReactMarkdown@@ -31,8 +35,8 @@ describe("memo content lists", () => {expect(listOpenTags[1]).not.toContain(TASK_LIST_CLASS);expect(listOpenTags[1]).toContain("ps-6");expect(listOpenTags[1]).toContain("list-disc");- expect(html).toContain('<li class="mt-0.5 leading-6">milk</li>');- expect(html).not.toContain('<li class="mt-0.5 leading-6">\n<p>milk</p>');+ expect(html).toContain(`<li class="${listItemClass}">milk</li>`);+ expect(html).not.toContain(`<li class="${listItemClass}">\n<p>milk</p>`);expect(html).toContain(TASK_LIST_ITEM_CLASS);expect(html).toContain("grid grid-cols-[auto_minmax(0,1fr)] items-start gap-x-2");expect(html).toContain('<div class="min-w-0 [overflow-wrap:anywhere] [&>*:last-child]:mb-0"> pickup package</div>');