Skip to content

Commit 39f523b

Browse files
authored
fix: editing presenter notes on frontmatter-only slides (#2591)
1 parent 6d1a84a commit 39f523b

4 files changed

Lines changed: 42 additions & 8 deletions

File tree

packages/client/internals/SideEditor.vue

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { throttledWatch, useEventListener } from '@vueuse/core'
33
import { computed, ref, watch } from 'vue'
44
import { useNav } from '../composables/useNav'
55
import { useDynamicSlideInfo } from '../composables/useSlideInfo'
6+
import { parseSideEditorContent } from '../logic/sideEditor'
67
import { activeElement, editorHeight, editorWidth, isInputting, showEditor, isEditorVertical as vertical } from '../state'
78
import IconButton from './IconButton.vue'
89
import ShikiEditor from './ShikiEditor.vue'
@@ -11,8 +12,6 @@ const props = defineProps<{
1112
resize?: boolean
1213
}>()
1314
14-
const RE_FRONTMATTER_BLOCK = /^---\n([\s\S]*?)\n---\n/
15-
1615
const { currentSlideNo, openInEditor } = useNav()
1716
1817
const tab = ref<'content' | 'note'>('content')
@@ -38,11 +37,7 @@ watch(
3837
async function save() {
3938
dirty.value = false
4039
41-
let frontmatterRaw: string | undefined
42-
const contentOnly = content.value.trim().replace(RE_FRONTMATTER_BLOCK, (_, f) => {
43-
frontmatterRaw = f
44-
return ''
45-
})
40+
const { content: contentOnly, frontmatterRaw } = parseSideEditorContent(content.value)
4641
4742
await update({
4843
note: note.value || undefined,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const RE_FRONTMATTER_BLOCK = /^---\n([\s\S]*?)\n---(?:\n|$)/
2+
3+
export function parseSideEditorContent(content: string) {
4+
let frontmatterRaw: string | undefined
5+
const contentOnly = content.trim().replace(RE_FRONTMATTER_BLOCK, (_, f) => {
6+
frontmatterRaw = f
7+
return ''
8+
})
9+
10+
return {
11+
content: contentOnly,
12+
frontmatterRaw,
13+
}
14+
}

packages/slidev/node/vite/loaders.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export function createSlidesLoader(
107107
slide.source.frontmatterDoc = parsed
108108
}
109109
}
110-
if (body.note)
110+
if (body.note != null)
111111
slide.note = slide.source.note = body.note
112112
if (body.frontmatter) {
113113
updateFrontmatterPatch(slide.source, body.frontmatter)

test/side-editor.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { parseSideEditorContent } from '../packages/client/logic/sideEditor'
3+
4+
describe('side editor', () => {
5+
it('extracts frontmatter-only slide content', () => {
6+
expect(parseSideEditorContent(`---
7+
layout: image
8+
image: /example.png
9+
---`)).toEqual({
10+
content: '',
11+
frontmatterRaw: 'layout: image\nimage: /example.png',
12+
})
13+
})
14+
15+
it('extracts frontmatter from slides with body content', () => {
16+
expect(parseSideEditorContent(`---
17+
layout: center
18+
---
19+
20+
# Hello`)).toEqual({
21+
content: '\n# Hello',
22+
frontmatterRaw: 'layout: center',
23+
})
24+
})
25+
})

0 commit comments

Comments
 (0)