Skip to content

Allow transforming slide notes #2134

Open
@akordowski

Description

@akordowski

Is your feature request related to a problem? Please describe.
In a scenario of a multi user slides each user should be able to add custom slide notes and override the existing one.

Describe the solution you'd like
Add in the slidev/packages/types/src/types.ts file after line 124 a new function to the SlidevPreparserExtension type:

transformNote?: (note: string, frontmatter: any) => Promise<string | undefined>

export interface SlidevPreparserExtension {
name?: string
transformRawLines?: (lines: string[]) => Promise<void> | void
transformSlide?: (content: string, frontmatter: any) => Promise<string | undefined>
}

Add in the slidev/packages/parser/src/core.ts file after line 158 a new call of the transformNote function:

if (e.transformNote) {
  const newNote = await e.transformNote(slide.note, slide.frontmatter)
  if (newNote !== undefined)
    slide.note = newNote
}

if (extensions) {
for (const e of extensions) {
if (e.transformSlide) {
const newContent = await e.transformSlide(slide.content, slide.frontmatter)
if (newContent !== undefined)
slide.content = newContent
if (typeof slide.frontmatter.title === 'string') {
slide.title = slide.frontmatter.title
}
if (typeof slide.frontmatter.level === 'number') {
slide.level = slide.frontmatter.level
}
}
}

Describe alternatives you've considered
I tried to solve it using the transformRawLines(lines) function, but it would require some custom logic, which would break the structure of the slides.md.

Example

A example could look like this:

---
layout: custom
_note: notes/note_1.md
---

Content

<!--
Default notes
-->

Using the transformNote function the notes could be replaced if the frontmatter contains the _notes property.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions