From b4e85d95a6dbcfbc2289ec20346a634555051623 Mon Sep 17 00:00:00 2001
From: Jinjing <6427696+AmethystLiang@users.noreply.github.com>
Date: Sun, 19 Jul 2026 12:13:16 -0700
Subject: [PATCH] feat(editor): add Toggle H5 to markdown editor (#9448)
---
src/renderer/src/assets/markdown-preview.css | 8 ++++-
.../src/assets/rich-markdown-editor.css | 9 +++++-
.../src/components/editor/MarkdownPreview.tsx | 2 +-
.../editor/details-markdown-html.test.ts | 29 +++++++++++++++++++
.../editor/details-markdown-html.ts | 18 ++++++++----
.../editor/markdown-round-trip.test.ts | 11 +++++--
.../editor/rich-markdown-commands.test.ts | 2 ++
.../editor/rich-markdown-details-extension.ts | 3 +-
.../rich-markdown-heading-slash-commands.tsx | 21 ++++++++++++++
.../rich-markdown-slash-command-primitives.ts | 1 +
src/renderer/src/i18n/locales/en.json | 4 ++-
src/renderer/src/i18n/locales/es.json | 4 ++-
src/renderer/src/i18n/locales/ja.json | 4 ++-
src/renderer/src/i18n/locales/ko.json | 4 ++-
src/renderer/src/i18n/locales/zh.json | 4 ++-
15 files changed, 107 insertions(+), 17 deletions(-)
diff --git a/src/renderer/src/assets/markdown-preview.css b/src/renderer/src/assets/markdown-preview.css
index 9388731bb9c..7f5afaf76f1 100644
--- a/src/renderer/src/assets/markdown-preview.css
+++ b/src/renderer/src/assets/markdown-preview.css
@@ -556,7 +556,7 @@
line-height: 1.3;
}
-/* Heading toggle sizes mirror the plain h2–h4 scales (1.4 / 1.15 / 1em). */
+/* Heading toggle sizes mirror the plain h2–h5 scales (1.4 / 1.15 / 1 / 0.92em). */
.markdown-body details.orca-details[data-orca-toggle='heading-2'] > summary {
font-size: 1.4em;
line-height: 1.3;
@@ -572,6 +572,12 @@
line-height: 1.3;
}
+.markdown-body details.orca-details[data-orca-toggle='heading-5'] > summary {
+ font-size: 0.92em;
+ color: var(--muted-foreground);
+ line-height: 1.3;
+}
+
.markdown-body details.orca-details > :not(summary) {
margin-left: 0.15em;
}
diff --git a/src/renderer/src/assets/rich-markdown-editor.css b/src/renderer/src/assets/rich-markdown-editor.css
index 48c13e0057d..4b918455221 100644
--- a/src/renderer/src/assets/rich-markdown-editor.css
+++ b/src/renderer/src/assets/rich-markdown-editor.css
@@ -764,7 +764,7 @@
height: 2.405em;
}
-/* Heading toggle sizes mirror the plain h2–h4 scales (1.4 / 1.15 / 1em). */
+/* Heading toggle sizes mirror the plain h2–h5 scales (1.4 / 1.15 / 1 / 0.92em). */
.rich-markdown-editor details.orca-details[data-orca-toggle='heading-2'] > summary,
.rich-markdown-editor .orca-details[data-type='details'][data-orca-toggle='heading-2'] summary {
font-size: 1.4em;
@@ -787,6 +787,13 @@
line-height: 1.3;
}
+.rich-markdown-editor details.orca-details[data-orca-toggle='heading-5'] > summary,
+.rich-markdown-editor .orca-details[data-type='details'][data-orca-toggle='heading-5'] summary {
+ font-size: 0.92em;
+ color: var(--muted-foreground);
+ line-height: 1.3;
+}
+
.rich-markdown-editor blockquote {
padding: 0.5em 1em;
border-left: 3px solid var(--border);
diff --git a/src/renderer/src/components/editor/MarkdownPreview.tsx b/src/renderer/src/components/editor/MarkdownPreview.tsx
index 4c09bd0a8b5..3fa53012683 100644
--- a/src/renderer/src/components/editor/MarkdownPreview.tsx
+++ b/src/renderer/src/components/editor/MarkdownPreview.tsx
@@ -315,7 +315,7 @@ const markdownPreviewSanitizeSchema = {
...(defaultSchema.attributes?.details ?? []),
'open',
['className', 'orca-details'],
- ['dataOrcaToggle', 'heading-1', 'heading-2', 'heading-3', 'heading-4']
+ ['dataOrcaToggle', 'heading-1', 'heading-2', 'heading-3', 'heading-4', 'heading-5']
],
h1: [...(defaultSchema.attributes?.h1 ?? []), 'id'],
h2: [...(defaultSchema.attributes?.h2 ?? []), 'id'],
diff --git a/src/renderer/src/components/editor/details-markdown-html.test.ts b/src/renderer/src/components/editor/details-markdown-html.test.ts
index e381f453835..c4e1493a198 100644
--- a/src/renderer/src/components/editor/details-markdown-html.test.ts
+++ b/src/renderer/src/components/editor/details-markdown-html.test.ts
@@ -2,6 +2,8 @@ import { afterEach, describe, expect, it, vi } from 'vitest'
import {
extractDetailsSummaryHtml,
isEditableDetailsHtmlBlock,
+ parseDetailsAttributes,
+ parseToggleHeadingVariant,
type DetailsHtmlBlock
} from './details-markdown-html'
@@ -45,4 +47,31 @@ describe('details markdown html', () => {
)
expect(usedSummaryCapture).toBe(false)
})
+
+ it('accepts heading-5 toggle variants and rejects unsupported levels', () => {
+ expect(parseToggleHeadingVariant('heading-5')).toBe('heading-5')
+ expect(parseToggleHeadingVariant('heading-6')).toBeNull()
+ expect(parseDetailsAttributes(' data-orca-toggle="heading-5"')).toMatchObject({
+ variant: 'heading-5'
+ })
+ expect(parseDetailsAttributes(' data-orca-toggle="heading-6"')).toMatchObject({
+ variant: null
+ })
+
+ const editableHeading5: DetailsHtmlBlock = {
+ raw: '',
+ openingAttributes: ' data-orca-toggle="heading-5"',
+ inner: '
Body
', + hasNestedDetails: false + } + const unsupportedHeading6: DetailsHtmlBlock = { + raw: '', + openingAttributes: ' data-orca-toggle="heading-6"', + inner: 'Body
', + hasNestedDetails: false + } + + expect(isEditableDetailsHtmlBlock(editableHeading5)).toBe(true) + expect(isEditableDetailsHtmlBlock(unsupportedHeading6)).toBe(false) + }) }) diff --git a/src/renderer/src/components/editor/details-markdown-html.ts b/src/renderer/src/components/editor/details-markdown-html.ts index 6534793ce63..a2f4238b658 100644 --- a/src/renderer/src/components/editor/details-markdown-html.ts +++ b/src/renderer/src/components/editor/details-markdown-html.ts @@ -1,14 +1,20 @@ import type { MarkdownToken } from '@tiptap/core' -// Toggle summaries can render at heading scales 1–4, mirroring the plain -// heading levels the slash menu / toolbar dropdown offer (h1–h4). -export type ToggleHeadingVariant = 'heading-1' | 'heading-2' | 'heading-3' | 'heading-4' +// Toggle summaries can render at heading scales 1–5, mirroring the plain +// heading levels the slash menu / toolbar dropdown offer (h1–h5). +export type ToggleHeadingVariant = + | 'heading-1' + | 'heading-2' + | 'heading-3' + | 'heading-4' + | 'heading-5' export const TOGGLE_HEADING_VARIANTS: readonly ToggleHeadingVariant[] = [ 'heading-1', 'heading-2', 'heading-3', - 'heading-4' + 'heading-4', + 'heading-5' ] export function parseToggleHeadingVariant(value: unknown): ToggleHeadingVariant | null { @@ -49,7 +55,7 @@ export function parseDetailsAttributes(rawAttributes: string): RecordBody