Skip to content

Commit 9c32388

Browse files
jgosmannkermanx
andauthoredMar 31, 2025··
fix: load raw slide content in slide editor (#2094)
* fix: load raw slide content in slide editor Fixes #1579. Otherwise, the editor would load the preprocessed content and overwrite the unprocessed content. * chore: add comment --------- Co-authored-by: _Kerman <kermanx@qq.com>
1 parent dc8b462 commit 9c32388

File tree

4 files changed

+153
-1
lines changed

4 files changed

+153
-1
lines changed
 

‎packages/client/internals/SideEditor.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ watch(
2626
if (!isInputting.value) {
2727
note.value = (v?.note || '').trim()
2828
const frontmatterPart = v?.frontmatterRaw?.trim() ? `---\n${v.frontmatterRaw.trim()}\n---\n\n` : ''
29-
content.value = frontmatterPart + (v?.content || '').trim()
29+
content.value = frontmatterPart + (v?.source.contentRaw || '').trim()
3030
dirty.value = false
3131
}
3232
},

‎packages/parser/src/core.ts

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export function parseSlide(raw: string, options: SlidevParserOptions = {}): Omit
110110
level,
111111
revision,
112112
content,
113+
contentRaw: content,
113114
frontmatter,
114115
frontmatterStyle: matterResult.type,
115116
frontmatterDoc: matterResult.doc,

‎packages/types/src/types.ts

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export interface SourceSlideInfo extends SlideInfoBase {
3131
contentStart: number
3232
end: number
3333
raw: string
34+
/**
35+
* Raw content before being processed by preparsers (if any)
36+
*/
37+
contentRaw: string
3438
/**
3539
* Slides import by this slide.
3640
*/

‎test/__snapshots__/parser.test.ts.snap

+147
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ fonts:
103103
"content": "
104104
# Hi
105105
",
106+
"contentRaw": "# Hi",
106107
"contentStart": 7,
107108
"end": 10,
108109
"filepath": "frontmatter.md",
@@ -171,6 +172,7 @@ layout: center
171172
"content": "
172173
# Hello
173174
",
175+
"contentRaw": "# Hello",
174176
"contentStart": 16,
175177
"end": 23,
176178
"filepath": "frontmatter.md",
@@ -229,6 +231,7 @@ This is note
229231
"content": "
230232
# Morning
231233
",
234+
"contentRaw": "# Morning",
232235
"contentStart": 24,
233236
"end": 27,
234237
"filepath": "frontmatter.md",
@@ -266,6 +269,8 @@ Hey",
266269
<!-- This is not note -->
267270
Hey
268271
",
272+
"contentRaw": "<!-- This is not note -->
273+
Hey",
269274
"contentStart": 30,
270275
"end": 38,
271276
"filepath": "frontmatter.md",
@@ -327,6 +332,15 @@ this should be treated as code block
327332
Also part of the code block
328333
\`\`\`
329334
",
335+
"contentRaw": "\`\`\`md
336+
---
337+
this should be treated as code block
338+
---
339+
340+
---
341+
342+
Also part of the code block
343+
\`\`\`",
330344
"contentStart": 39,
331345
"end": 50,
332346
"filepath": "frontmatter.md",
@@ -372,6 +386,7 @@ layout: from yaml
372386
"content": "
373387
Content 1
374388
",
389+
"contentRaw": "Content 1",
375390
"contentStart": 51,
376391
"end": 59,
377392
"filepath": "frontmatter.md",
@@ -428,6 +443,12 @@ layout: should not from yaml 1
428443
429444
Content 2
430445
",
446+
"contentRaw": "\`\`\`yaml
447+
# When there is already a frontmatter, the first yaml block should be treated as content
448+
layout: should not from yaml 1
449+
\`\`\`
450+
451+
Content 2",
431452
"contentStart": 62,
432453
"end": 70,
433454
"filepath": "frontmatter.md",
@@ -487,6 +508,14 @@ layout: should not from yaml 2
487508
488509
Content 3
489510
",
511+
"contentRaw": "# Title
512+
513+
\`\`\`yaml
514+
# When there is already a frontmatter, the first yaml block should be treated as content
515+
layout: should not from yaml 2
516+
\`\`\`
517+
518+
Content 3",
490519
"contentStart": 71,
491520
"end": 81,
492521
"filepath": "frontmatter.md",
@@ -605,6 +634,9 @@ exports[`md parser > mdc.md > slides 1`] = `
605634
606635
:arrow{x1=1 y1=1 x2=2 y2=2}
607636
",
637+
"contentRaw": "# MDC{style="color:red"}
638+
639+
:arrow{x1=1 y1=1 x2=2 y2=2}",
608640
"contentStart": 3,
609641
"end": 8,
610642
"filepath": "mdc.md",
@@ -734,6 +766,15 @@ Sample Text
734766
console.log('Hello World')
735767
\`\`\`
736768
",
769+
"contentRaw": "# H1
770+
## H2
771+
### H3
772+
773+
Sample Text
774+
775+
\`\`\`ts
776+
console.log('Hello World')
777+
\`\`\`",
737778
"contentStart": 0,
738779
"end": 10,
739780
"filepath": "minimal.md",
@@ -784,6 +825,12 @@ console.log('Hello World')
784825
- Hey
785826
- Yo
786827
",
828+
"contentRaw": "# Hello
829+
830+
- Hello
831+
- Hi
832+
- Hey
833+
- Yo",
787834
"contentStart": 11,
788835
"end": 19,
789836
"filepath": "minimal.md",
@@ -821,6 +868,7 @@ console.log('Hello World')
821868
"content": "
822869
Nice to meet you
823870
",
871+
"contentRaw": "Nice to meet you",
824872
"contentStart": 20,
825873
"end": 23,
826874
"filepath": "minimal.md",
@@ -919,6 +967,7 @@ exports[`md parser > multi-entries.md > slides 1`] = `
919967
"importChain": [
920968
{
921969
"content": "",
970+
"contentRaw": "",
922971
"contentStart": 3,
923972
"end": 4,
924973
"filepath": "multi-entries.md",
@@ -934,6 +983,7 @@ exports[`md parser > multi-entries.md > slides 1`] = `
934983
"imports": [
935984
{
936985
"content": "# Page 1",
986+
"contentRaw": "# Page 1",
937987
"contentStart": 0,
938988
"end": 2,
939989
"filepath": "sub/page1.md",
@@ -969,6 +1019,7 @@ src: sub/page1.md
9691019
"revision": "q9078d",
9701020
"source": {
9711021
"content": "# Page 1",
1022+
"contentRaw": "# Page 1",
9721023
"contentStart": 0,
9731024
"end": 2,
9741025
"filepath": "sub/page1.md",
@@ -1000,6 +1051,7 @@ src: sub/page1.md
10001051
"importChain": [
10011052
{
10021053
"content": "",
1054+
"contentRaw": "",
10031055
"contentStart": 8,
10041056
"end": 9,
10051057
"filepath": "multi-entries.md",
@@ -1019,6 +1071,9 @@ background: https://sli.dev/demo-cover.png#2
10191071
{
10201072
"content": "# Page 2
10211073
1074+
<Tweet />",
1075+
"contentRaw": "# Page 2
1076+
10221077
<Tweet />",
10231078
"contentStart": 3,
10241079
"end": 8,
@@ -1068,6 +1123,9 @@ background: https://sli.dev/demo-cover.png#2
10681123
"source": {
10691124
"content": "# Page 2
10701125
1126+
<Tweet />",
1127+
"contentRaw": "# Page 2
1128+
10711129
<Tweet />",
10721130
"contentStart": 3,
10731131
"end": 8,
@@ -1107,6 +1165,7 @@ layout: cover
11071165
"importChain": [
11081166
{
11091167
"content": "",
1168+
"contentRaw": "",
11101169
"contentStart": 13,
11111170
"end": 14,
11121171
"filepath": "multi-entries.md",
@@ -1125,6 +1184,7 @@ background: https://sli.dev/demo-cover.png#34
11251184
"imports": [
11261185
{
11271186
"content": "# Page 3",
1187+
"contentRaw": "# Page 3",
11281188
"contentStart": 0,
11291189
"end": 2,
11301190
"filepath": "sub/pages3-4.md",
@@ -1144,6 +1204,9 @@ background: https://sli.dev/demo-cover.png#34
11441204
{
11451205
"content": "# Page 4
11461206
1207+
<Tweet />",
1208+
"contentRaw": "# Page 4
1209+
11471210
<Tweet />",
11481211
"contentStart": 5,
11491212
"end": 10,
@@ -1192,6 +1255,7 @@ background: https://sli.dev/demo-cover.png#34
11921255
"revision": "q9078f",
11931256
"source": {
11941257
"content": "# Page 3",
1258+
"contentRaw": "# Page 3",
11951259
"contentStart": 0,
11961260
"end": 2,
11971261
"filepath": "sub/pages3-4.md",
@@ -1223,6 +1287,7 @@ background: https://sli.dev/demo-cover.png#34
12231287
"importChain": [
12241288
{
12251289
"content": "",
1290+
"contentRaw": "",
12261291
"contentStart": 13,
12271292
"end": 14,
12281293
"filepath": "multi-entries.md",
@@ -1241,6 +1306,7 @@ background: https://sli.dev/demo-cover.png#34
12411306
"imports": [
12421307
{
12431308
"content": "# Page 3",
1309+
"contentRaw": "# Page 3",
12441310
"contentStart": 0,
12451311
"end": 2,
12461312
"filepath": "sub/pages3-4.md",
@@ -1260,6 +1326,9 @@ background: https://sli.dev/demo-cover.png#34
12601326
{
12611327
"content": "# Page 4
12621328
1329+
<Tweet />",
1330+
"contentRaw": "# Page 4
1331+
12631332
<Tweet />",
12641333
"contentStart": 5,
12651334
"end": 10,
@@ -1309,6 +1378,9 @@ background: https://sli.dev/demo-cover.png#34
13091378
"source": {
13101379
"content": "# Page 4
13111380
1381+
<Tweet />",
1382+
"contentRaw": "# Page 4
1383+
13121384
<Tweet />",
13131385
"contentStart": 5,
13141386
"end": 10,
@@ -1348,6 +1420,7 @@ layout: cover
13481420
"importChain": [
13491421
{
13501422
"content": "",
1423+
"contentRaw": "",
13511424
"contentStart": 18,
13521425
"end": 19,
13531426
"filepath": "multi-entries.md",
@@ -1366,6 +1439,7 @@ background: https://sli.dev/demo-cover.png#14
13661439
"imports": [
13671440
{
13681441
"content": "",
1442+
"contentRaw": "",
13691443
"contentStart": 3,
13701444
"end": 4,
13711445
"filepath": "sub/nested1-4.md",
@@ -1381,6 +1455,7 @@ background: https://sli.dev/demo-cover.png#14
13811455
"imports": [
13821456
{
13831457
"content": "# Page 1",
1458+
"contentRaw": "# Page 1",
13841459
"contentStart": 0,
13851460
"end": 2,
13861461
"filepath": "sub/page1.md",
@@ -1411,6 +1486,7 @@ src: /sub/page1.md
14111486
},
14121487
{
14131488
"content": "",
1489+
"contentRaw": "",
14141490
"contentStart": 7,
14151491
"end": 8,
14161492
"filepath": "sub/nested1-4.md",
@@ -1427,6 +1503,9 @@ src: /sub/page1.md
14271503
{
14281504
"content": "# Page 2
14291505
1506+
<Tweet />",
1507+
"contentRaw": "# Page 2
1508+
14301509
<Tweet />",
14311510
"contentStart": 3,
14321511
"end": 8,
@@ -1469,6 +1548,7 @@ src: page2.md
14691548
},
14701549
{
14711550
"content": "",
1551+
"contentRaw": "",
14721552
"contentStart": 11,
14731553
"end": 12,
14741554
"filepath": "sub/nested1-4.md",
@@ -1484,6 +1564,7 @@ src: page2.md
14841564
"imports": [
14851565
{
14861566
"content": "# Page 3",
1567+
"contentRaw": "# Page 3",
14871568
"contentStart": 0,
14881569
"end": 2,
14891570
"filepath": "sub/pages3-4.md",
@@ -1503,6 +1584,9 @@ src: page2.md
15031584
{
15041585
"content": "# Page 4
15051586
1587+
<Tweet />",
1588+
"contentRaw": "# Page 4
1589+
15061590
<Tweet />",
15071591
"contentStart": 5,
15081592
"end": 10,
@@ -1558,6 +1642,7 @@ background: https://sli.dev/demo-cover.png#14
15581642
},
15591643
{
15601644
"content": "",
1645+
"contentRaw": "",
15611646
"contentStart": 3,
15621647
"end": 4,
15631648
"filepath": "sub/nested1-4.md",
@@ -1573,6 +1658,7 @@ background: https://sli.dev/demo-cover.png#14
15731658
"imports": [
15741659
{
15751660
"content": "# Page 1",
1661+
"contentRaw": "# Page 1",
15761662
"contentStart": 0,
15771663
"end": 2,
15781664
"filepath": "sub/page1.md",
@@ -1608,6 +1694,7 @@ src: /sub/page1.md
16081694
"revision": "q9078d",
16091695
"source": {
16101696
"content": "# Page 1",
1697+
"contentRaw": "# Page 1",
16111698
"contentStart": 0,
16121699
"end": 2,
16131700
"filepath": "sub/page1.md",
@@ -1639,6 +1726,7 @@ src: /sub/page1.md
16391726
"importChain": [
16401727
{
16411728
"content": "",
1729+
"contentRaw": "",
16421730
"contentStart": 18,
16431731
"end": 19,
16441732
"filepath": "multi-entries.md",
@@ -1657,6 +1745,7 @@ background: https://sli.dev/demo-cover.png#14
16571745
"imports": [
16581746
{
16591747
"content": "",
1748+
"contentRaw": "",
16601749
"contentStart": 3,
16611750
"end": 4,
16621751
"filepath": "sub/nested1-4.md",
@@ -1672,6 +1761,7 @@ background: https://sli.dev/demo-cover.png#14
16721761
"imports": [
16731762
{
16741763
"content": "# Page 1",
1764+
"contentRaw": "# Page 1",
16751765
"contentStart": 0,
16761766
"end": 2,
16771767
"filepath": "sub/page1.md",
@@ -1702,6 +1792,7 @@ src: /sub/page1.md
17021792
},
17031793
{
17041794
"content": "",
1795+
"contentRaw": "",
17051796
"contentStart": 7,
17061797
"end": 8,
17071798
"filepath": "sub/nested1-4.md",
@@ -1718,6 +1809,9 @@ src: /sub/page1.md
17181809
{
17191810
"content": "# Page 2
17201811
1812+
<Tweet />",
1813+
"contentRaw": "# Page 2
1814+
17211815
<Tweet />",
17221816
"contentStart": 3,
17231817
"end": 8,
@@ -1760,6 +1854,7 @@ src: page2.md
17601854
},
17611855
{
17621856
"content": "",
1857+
"contentRaw": "",
17631858
"contentStart": 11,
17641859
"end": 12,
17651860
"filepath": "sub/nested1-4.md",
@@ -1775,6 +1870,7 @@ src: page2.md
17751870
"imports": [
17761871
{
17771872
"content": "# Page 3",
1873+
"contentRaw": "# Page 3",
17781874
"contentStart": 0,
17791875
"end": 2,
17801876
"filepath": "sub/pages3-4.md",
@@ -1794,6 +1890,9 @@ src: page2.md
17941890
{
17951891
"content": "# Page 4
17961892
1893+
<Tweet />",
1894+
"contentRaw": "# Page 4
1895+
17971896
<Tweet />",
17981897
"contentStart": 5,
17991898
"end": 10,
@@ -1849,6 +1948,7 @@ background: https://sli.dev/demo-cover.png#14
18491948
},
18501949
{
18511950
"content": "",
1951+
"contentRaw": "",
18521952
"contentStart": 7,
18531953
"end": 8,
18541954
"filepath": "sub/nested1-4.md",
@@ -1865,6 +1965,9 @@ background: https://sli.dev/demo-cover.png#14
18651965
{
18661966
"content": "# Page 2
18671967
1968+
<Tweet />",
1969+
"contentRaw": "# Page 2
1970+
18681971
<Tweet />",
18691972
"contentStart": 3,
18701973
"end": 8,
@@ -1913,6 +2016,9 @@ src: page2.md
19132016
"source": {
19142017
"content": "# Page 2
19152018
2019+
<Tweet />",
2020+
"contentRaw": "# Page 2
2021+
19162022
<Tweet />",
19172023
"contentStart": 3,
19182024
"end": 8,
@@ -1952,6 +2058,7 @@ layout: cover
19522058
"importChain": [
19532059
{
19542060
"content": "",
2061+
"contentRaw": "",
19552062
"contentStart": 18,
19562063
"end": 19,
19572064
"filepath": "multi-entries.md",
@@ -1970,6 +2077,7 @@ background: https://sli.dev/demo-cover.png#14
19702077
"imports": [
19712078
{
19722079
"content": "",
2080+
"contentRaw": "",
19732081
"contentStart": 3,
19742082
"end": 4,
19752083
"filepath": "sub/nested1-4.md",
@@ -1985,6 +2093,7 @@ background: https://sli.dev/demo-cover.png#14
19852093
"imports": [
19862094
{
19872095
"content": "# Page 1",
2096+
"contentRaw": "# Page 1",
19882097
"contentStart": 0,
19892098
"end": 2,
19902099
"filepath": "sub/page1.md",
@@ -2015,6 +2124,7 @@ src: /sub/page1.md
20152124
},
20162125
{
20172126
"content": "",
2127+
"contentRaw": "",
20182128
"contentStart": 7,
20192129
"end": 8,
20202130
"filepath": "sub/nested1-4.md",
@@ -2031,6 +2141,9 @@ src: /sub/page1.md
20312141
{
20322142
"content": "# Page 2
20332143
2144+
<Tweet />",
2145+
"contentRaw": "# Page 2
2146+
20342147
<Tweet />",
20352148
"contentStart": 3,
20362149
"end": 8,
@@ -2073,6 +2186,7 @@ src: page2.md
20732186
},
20742187
{
20752188
"content": "",
2189+
"contentRaw": "",
20762190
"contentStart": 11,
20772191
"end": 12,
20782192
"filepath": "sub/nested1-4.md",
@@ -2088,6 +2202,7 @@ src: page2.md
20882202
"imports": [
20892203
{
20902204
"content": "# Page 3",
2205+
"contentRaw": "# Page 3",
20912206
"contentStart": 0,
20922207
"end": 2,
20932208
"filepath": "sub/pages3-4.md",
@@ -2107,6 +2222,9 @@ src: page2.md
21072222
{
21082223
"content": "# Page 4
21092224
2225+
<Tweet />",
2226+
"contentRaw": "# Page 4
2227+
21102228
<Tweet />",
21112229
"contentStart": 5,
21122230
"end": 10,
@@ -2162,6 +2280,7 @@ background: https://sli.dev/demo-cover.png#14
21622280
},
21632281
{
21642282
"content": "",
2283+
"contentRaw": "",
21652284
"contentStart": 11,
21662285
"end": 12,
21672286
"filepath": "sub/nested1-4.md",
@@ -2177,6 +2296,7 @@ background: https://sli.dev/demo-cover.png#14
21772296
"imports": [
21782297
{
21792298
"content": "# Page 3",
2299+
"contentRaw": "# Page 3",
21802300
"contentStart": 0,
21812301
"end": 2,
21822302
"filepath": "sub/pages3-4.md",
@@ -2196,6 +2316,9 @@ background: https://sli.dev/demo-cover.png#14
21962316
{
21972317
"content": "# Page 4
21982318
2319+
<Tweet />",
2320+
"contentRaw": "# Page 4
2321+
21992322
<Tweet />",
22002323
"contentStart": 5,
22012324
"end": 10,
@@ -2243,6 +2366,7 @@ src: ../sub/pages3-4.md
22432366
"revision": "q9078f",
22442367
"source": {
22452368
"content": "# Page 3",
2369+
"contentRaw": "# Page 3",
22462370
"contentStart": 0,
22472371
"end": 2,
22482372
"filepath": "sub/pages3-4.md",
@@ -2274,6 +2398,7 @@ src: ../sub/pages3-4.md
22742398
"importChain": [
22752399
{
22762400
"content": "",
2401+
"contentRaw": "",
22772402
"contentStart": 18,
22782403
"end": 19,
22792404
"filepath": "multi-entries.md",
@@ -2292,6 +2417,7 @@ background: https://sli.dev/demo-cover.png#14
22922417
"imports": [
22932418
{
22942419
"content": "",
2420+
"contentRaw": "",
22952421
"contentStart": 3,
22962422
"end": 4,
22972423
"filepath": "sub/nested1-4.md",
@@ -2307,6 +2433,7 @@ background: https://sli.dev/demo-cover.png#14
23072433
"imports": [
23082434
{
23092435
"content": "# Page 1",
2436+
"contentRaw": "# Page 1",
23102437
"contentStart": 0,
23112438
"end": 2,
23122439
"filepath": "sub/page1.md",
@@ -2337,6 +2464,7 @@ src: /sub/page1.md
23372464
},
23382465
{
23392466
"content": "",
2467+
"contentRaw": "",
23402468
"contentStart": 7,
23412469
"end": 8,
23422470
"filepath": "sub/nested1-4.md",
@@ -2353,6 +2481,9 @@ src: /sub/page1.md
23532481
{
23542482
"content": "# Page 2
23552483
2484+
<Tweet />",
2485+
"contentRaw": "# Page 2
2486+
23562487
<Tweet />",
23572488
"contentStart": 3,
23582489
"end": 8,
@@ -2395,6 +2526,7 @@ src: page2.md
23952526
},
23962527
{
23972528
"content": "",
2529+
"contentRaw": "",
23982530
"contentStart": 11,
23992531
"end": 12,
24002532
"filepath": "sub/nested1-4.md",
@@ -2410,6 +2542,7 @@ src: page2.md
24102542
"imports": [
24112543
{
24122544
"content": "# Page 3",
2545+
"contentRaw": "# Page 3",
24132546
"contentStart": 0,
24142547
"end": 2,
24152548
"filepath": "sub/pages3-4.md",
@@ -2429,6 +2562,9 @@ src: page2.md
24292562
{
24302563
"content": "# Page 4
24312564
2565+
<Tweet />",
2566+
"contentRaw": "# Page 4
2567+
24322568
<Tweet />",
24332569
"contentStart": 5,
24342570
"end": 10,
@@ -2484,6 +2620,7 @@ background: https://sli.dev/demo-cover.png#14
24842620
},
24852621
{
24862622
"content": "",
2623+
"contentRaw": "",
24872624
"contentStart": 11,
24882625
"end": 12,
24892626
"filepath": "sub/nested1-4.md",
@@ -2499,6 +2636,7 @@ background: https://sli.dev/demo-cover.png#14
24992636
"imports": [
25002637
{
25012638
"content": "# Page 3",
2639+
"contentRaw": "# Page 3",
25022640
"contentStart": 0,
25032641
"end": 2,
25042642
"filepath": "sub/pages3-4.md",
@@ -2518,6 +2656,9 @@ background: https://sli.dev/demo-cover.png#14
25182656
{
25192657
"content": "# Page 4
25202658
2659+
<Tweet />",
2660+
"contentRaw": "# Page 4
2661+
25212662
<Tweet />",
25222663
"contentStart": 5,
25232664
"end": 10,
@@ -2566,6 +2707,9 @@ src: ../sub/pages3-4.md
25662707
"source": {
25672708
"content": "# Page 4
25682709
2710+
<Tweet />",
2711+
"contentRaw": "# Page 4
2712+
25692713
<Tweet />",
25702714
"contentStart": 5,
25712715
"end": 10,
@@ -2613,6 +2757,9 @@ $x+2$",
26132757
26142758
$x+2$
26152759
",
2760+
"contentRaw": "# Inline Page
2761+
2762+
$x+2$",
26162763
"contentStart": 20,
26172764
"end": 25,
26182765
"filepath": "multi-entries.md",

0 commit comments

Comments
 (0)
Please sign in to comment.