gnab / remark

A simple, in-browser, markdown-driven slideshow tool.
http://remarkjs.com
MIT License
12.68k stars 856 forks source link

Implement multi-slide macros #587

Closed yeldiRium closed 4 years ago

yeldiRium commented 4 years ago

Hi!

Since I wanted to use the macros to stagger lists into slides and needed to generate multiple slides with macros as suggested in #488, I implemented the feature.

The behavior is now: When a macro is used inline and emits multiple slides, the first slide emitted is appended to the currently active slide, which is then pushed. The following slides are all pushed except the last one, which becomes the new active slide on the stack.

My reasoning for this behavior is the following scenario:

...
---

![:stagger](
# headline

%%%
- list element
  - sub element
  - sub element
%%%
- list element
%%%
- list element
%%%
- list element
%%%
- list element
%%%
- list element
)

---
...

With this macro implementation:

remark.macros.stagger = function () {
  return this.split('%%%\n').reduce(({ output, current }, part) => {
    const next = current + part
    return {
      output: output + next + '---\n',
      current: next
    }
  }, { output: '', current: '' }).output;
}

Looking forward to any feedback and with kind regards, yeldiR

utdrmac commented 4 years ago

What does this do that the standard way does not?

---
## header of slide

* topic 1
--
  * sub topic 1a
--
  * sub topic 1b
--
* topic 2
--
* topic 3
yeldiRium commented 4 years ago

Your example creates multiple slides with one part of the list each, right? Or am I missing a feature?

I want to create multiple pages with an incrementally larger part of the list showing. As I see it that is currently not possible with or without macros.

utdrmac commented 4 years ago

Here's what I get with the standard stuff. This looks to me like "multiple pages with an incrementally larger part of the list"

incremental.pdf incremental-bullet.html

yeldiRium commented 4 years ago

Huh. I wasn't aware of that. In that case, no macro is needed.

Thank you!

yeldiRium commented 4 years ago

The multi-page macro feature could of course be useful regardless, so if anyone needs it, feel free to reuse this pull request.