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 and slide editor #1579

Open
gureckis opened this issue May 9, 2024 · 0 comments
Open

interaction between preprocessor and slide editor #1579

gureckis opened this issue May 9, 2024 · 0 comments
Labels
bug Something isn't working needs discussion

Comments

@gureckis
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs discussion
Projects
None yet
Development

No branches or pull requests

2 participants