Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interaction between preprocessor/preparser and slide editor #1579

Open
gureckis opened this issue May 9, 2024 · 2 comments · May be fixed by #2094
Open

Interaction between preprocessor/preparser and slide editor #1579

gureckis opened this issue May 9, 2024 · 2 comments · May be fixed by #2094

Comments

@gureckis
Copy link
Contributor

gureckis commented May 9, 2024

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:

  1. 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(`---`)
        }
      },
    },
  ]
})
  1. open the slide in the slide editor
  2. 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
@twitwi twitwi changed the title interaction between preprocessor and slide editor Interaction between preprocessor/preparser and slide editor Aug 20, 2024
@twitwi
Copy link
Contributor

twitwi commented Aug 20, 2024

The preparser is for very specific uses cases and indeed breaks editor integration (we might want to highlight it more clearly in the documentation).

Having a full round trip edition is way too much work (and technically not always possible) compared to the gain.

I guess an improvement (still not so easy) would be to disallow the edition of slides in files that have been preparsed.

@jgosmann
Copy link
Contributor

jgosmann commented Mar 2, 2025

I ran into this today. To me it seems, that the editor should show the slide content from before preprocessing. Or am I missing something?

jgosmann added a commit to jgosmann/slidev that referenced this issue Mar 2, 2025
Fixes slidevjs#1579. Otherwise, the editor would load the preprocessed content and overwrite the unprocessed content.
@jgosmann jgosmann linked a pull request Mar 2, 2025 that will close this issue
jgosmann added a commit to jgosmann/slidev that referenced this issue Mar 2, 2025
Fixes slidevjs#1579. Otherwise, the editor would load the preprocessed content and overwrite the unprocessed content.
jgosmann added a commit to jgosmann/slidev that referenced this issue Mar 5, 2025
Fixes slidevjs#1579. Otherwise, the editor would load the preprocessed content and overwrite the unprocessed content.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants