Description
Describe the bug
This one is a little tricky and I apologize if misunderstanding how things should work. The preparser extensions (documented here) imply that your .md file is read in and then processed prior to be rendered. However, when using slide edit mode, the preprocessed file is written back out to disk. For example, in the example 1 where you replace your compact syntax notation, the idea is to make your markdown shorter. However, if you were to run this, then open the code in the slide editor would immediately overwrite your compact .md file with the expanded versions of these macros.
To Reproduce
Steps to reproduce the behavior:
- add a
setup/preparser.ts
file with something that adds new lines to the .md during preprocessing.
import { definePreparserSetup } from '@slidev/types'
export default definePreparserSetup(({ filepath, headmatter, mode }) => {
return [
{
transformRawLines(lines) {
// if front matter exists then insert at the top
// assumes you correctly ended the front matter with '---'
if (lines[0] === '---') {
lines.splice(1, 0, `filename: ${filepath}`)
} else {
// otherwise add frontmatter to first slide containing the file path
lines.unshift(`---`)
lines.unshift(`filename: ${filepath}`)
lines.unshift(`---`)
}
},
},
]
})
- open the slide in the slide editor
- observe that the .md file now has
filename: XXX
in the front matter defined twice (also there start being errors from the front matter preprocessor because in this case the change introduced two variables with the same name).
My expectation is that opening the slide editor while using the preparser shouldn't interact. Alternatively, this issue could be expected behavior in which case I'd mention that people should view the preprocessor as being applied multiple times to your file in the event you open the slide editor (so the code needs extra logic to handle that). Alternatively, the slidev should somehow write out to disk only the changes to the file from the slide editor but none of the changes rendered by the preparser.
Desktop (please complete the following information):
- Slidev version: v0.49.0-beta.6