Skip to content

Commit a2bd1ff

Browse files
chore(convert): improve HTML Jinja2 template (#443)
* chore(convert): improve HTML Jinja2 template As suggested by @yunusey in #442 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * chore(deps): fix importlib * fix: remove redundant if * fix(docs): rename PeculiarProgrammer to taibeled * chore: update template and doc. example * chore(docs): add changelog entry --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent e911ec3 commit a2bd1ff

File tree

6 files changed

+153
-254
lines changed

6 files changed

+153
-254
lines changed

CHANGELOG.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
for lightweight (and potentially faster) reversed animations generation.
2424
[#439](https://github.com/jeertmans/manim-slides/pull/439)
2525

26+
(unreleased-chore)=
27+
### Chore
28+
29+
- Trimmed whitespaces in HTML template.
30+
[#443](https://github.com/jeertmans/manim-slides/pull/443)
31+
2632
(v5.4.2)=
2733
## [v5.4.2](https://github.com/jeertmans/manim-slides/compare/v5.4.1...v5.4.2)
2834

@@ -104,7 +110,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
104110
was added to `manim-slides present` to force the info window.
105111
When there are multiple monitors, the info window will no longer
106112
be on the same monitor as the main window, unless overridden.
107-
[@PeculiarProgrammer](https://github.com/PeculiarProgrammer)
113+
[@taibeled](https://github.com/taibeled)
108114
[#482](https://github.com/jeertmans/manim-slides/pull/482)
109115

110116
(v5.2.0-chore)=
@@ -135,7 +141,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
135141
(v5.1.10-changed)=
136142
### Changed
137143

138-
- Allow multiple slide reverses by going backward [@PeculiarProgrammer](https://github.com/PeculiarProgrammer).
144+
- Allow multiple slide reverses by going backward [@taibeled](https://github.com/taibeled).
139145
[#488](https://github.com/jeertmans/manim-slides/pull/488)
140146

141147
(v5.1.10-fixed)=
@@ -208,7 +214,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
208214
- Fixed whitespace issue in default RevealJS template.
209215
[#442](https://github.com/jeertmans/manim-slides/pull/442)
210216
- Fixed black screen issue on recent Qt versions and device loss detected,
211-
thanks to [@PeculiarProgrammer](https://github.com/PeculiarProgrammer)!
217+
thanks to [@taibeled](https://github.com/taibeled)!
212218
[#465](https://github.com/jeertmans/manim-slides/pull/465)
213219

214220
(v5.1.8-removed)=

docs/source/_static/template.html

Lines changed: 35 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -18,82 +18,75 @@
1818
<body>
1919
<div class="reveal">
2020
<div class="slides">
21-
{%- for presentation_config in presentation_configs -%}
22-
{% set outer_loop = loop %}
23-
{%- for slide_config in presentation_config.slides -%}
24-
{%- if one_file -%}
21+
{% for presentation_config in presentation_configs -%}
22+
{%- set outer_loop = loop %}
23+
{% for slide_config in presentation_config.slides %}
24+
{% if one_file %}
2525
{% set file = file_to_data_uri(slide_config.file) %}
26-
{%- else -%}
27-
{% set file = assets_dir / slide_config.file.name %}
28-
{%- endif -%}
29-
<section
30-
data-background-size={{ background_size }}
31-
data-background-color="{{ presentation_config.background_color }}"
32-
data-background-video="{{ file }}"
33-
{% if loop.index == 1 and outer_loop.index == 1 -%}
34-
data-background-video-muted
35-
{%- endif %}
36-
{% if slide_config.loop -%}
37-
data-background-video-loop
38-
{%- endif -%}
39-
{% if slide_config.auto_next -%}
40-
data-autoslide="{{ get_duration_ms(slide_config.file) }}"
41-
{%- endif -%}>
42-
{% if slide_config.notes != "" -%}
43-
<aside class="notes" data-markdown>{{ slide_config.notes }}</aside>
44-
{%- endif %}
45-
</section>
46-
{%- endfor -%}
47-
{%- endfor -%}
26+
{% else %}
27+
{% set file = assets_dir / (prefix(outer_loop.index0) + slide_config.file.name) %}
28+
{% endif %}
29+
<section
30+
data-background-size={{ background_size }}
31+
data-background-color="{{ presentation_config.background_color }}"
32+
data-background-video="{{ file }}"
33+
{% if loop.index == 1 and outer_loop.index == 1 %}
34+
data-background-video-muted
35+
{% endif %}
36+
{% if slide_config.loop %}
37+
data-background-video-loop
38+
{% endif %}
39+
{% if slide_config.auto_next %}
40+
data-autoslide="{{ get_duration_ms(slide_config.file) }}"
41+
{% endif %}
42+
>
43+
{% if slide_config.notes != "" %}
44+
<aside class="notes" data-markdown>{{ slide_config.notes }}</aside>
45+
{% endif %}
46+
</section>
47+
{% endfor %}
48+
{% endfor %}
4849
</div>
4950
</div>
5051

5152
<script src="https://cdnjs.cloudflare.com/ajax/libs/reveal.js/{{ reveal_version }}/reveal.min.js"></script>
5253

5354
<!-- To include plugins, see: https://revealjs.com/plugins/ -->
54-
55-
{% if has_notes -%}
55+
{% if has_notes %}
5656
<script src="https://cdnjs.cloudflare.com/ajax/libs/reveal.js/{{ reveal_version }}/plugin/markdown/markdown.min.js"></script>
5757
<script src="https://cdnjs.cloudflare.com/ajax/libs/reveal.js/{{ reveal_version }}/plugin/notes/notes.min.js"></script>
58-
{%- endif -%}
58+
{% endif %}
5959

6060
<!-- <script src="index.js"></script> -->
6161
<script>
6262
Reveal.initialize({
63-
{% if has_notes -%}
64-
plugins: [ RevealMarkdown, RevealNotes ],
65-
{%- endif %}
63+
{% if has_notes %}
64+
/// The list of RevealJS plugins.
65+
plugins: [ RevealMarkdown, RevealNotes ],
66+
{% endif %}
6667
// The "normal" size of the presentation, aspect ratio will
6768
// be preserved when the presentation is scaled to fit different
6869
// resolutions. Can be specified using percentage units.
6970
width: {{ width }},
7071
height: {{ height }},
71-
7272
// Factor of the display size that should remain empty around
7373
// the content
7474
margin: {{ margin }},
75-
7675
// Bounds for smallest/largest possible scale to apply to content
7776
minScale: {{ min_scale }},
7877
maxScale: {{ max_scale }},
79-
8078
// Display presentation control arrows
8179
controls: {{ controls }},
82-
8380
// Help the user learn the controls by providing hints, for example by
8481
// bouncing the down arrow when they first encounter a vertical slide
8582
controlsTutorial: {{ controls_tutorial }},
86-
8783
// Determines where controls appear, "edges" or "bottom-right"
8884
controlsLayout: {{ controls_layout }},
89-
9085
// Visibility rule for backwards navigation arrows; "faded", "hidden"
9186
// or "visible"
9287
controlsBackArrows: {{ controls_back_arrows }},
93-
9488
// Display a presentation progress bar
9589
progress: {{ progress }},
96-
9790
// Display the page number of the current slide
9891
// - true: Show slide number
9992
// - false: Hide slide number
@@ -109,55 +102,43 @@
109102
// object and return an array with one string [slideNumber] or
110103
// three strings [n1,delimiter,n2]. See #formatSlideNumber().
111104
slideNumber: {{ slide_number }},
112-
113105
// Can be used to limit the contexts in which the slide number appears
114106
// - "all": Always show the slide number
115107
// - "print": Only when printing to PDF
116108
// - "speaker": Only in the speaker view
117109
showSlideNumber: {{ show_slide_number }},
118-
119110
// Use 1 based indexing for # links to match slide number (default is zero
120111
// based)
121112
hashOneBasedIndex: {{ hash_one_based_index }},
122-
123113
// Add the current slide number to the URL hash so that reloading the
124114
// page/copying the URL will return you to the same slide
125115
hash: {{ hash }},
126-
127116
// Flags if we should monitor the hash and change slides accordingly
128117
respondToHashChanges: {{ respond_to_hash_changes }},
129-
118+
// Enable support for jump-to-slide navigation shortcuts
119+
jumpToSlide: {{ jump_to_slide }},
130120
// Push each slide change to the browser history. Implies `hash: true`
131121
history: {{ history }},
132-
133122
// Enable keyboard shortcuts for navigation
134123
keyboard: {{ keyboard }},
135-
136124
// Optional function that blocks keyboard events when retuning false
137125
//
138126
// If you set this to 'focused', we will only capture keyboard events
139127
// for embedded decks when they are in focus
140128
keyboardCondition: {{ keyboard_condition }},
141-
142129
// Disables the default reveal.js slide layout (scaling and centering)
143130
// so that you can use custom CSS layout
144131
disableLayout: {{ disable_layout }},
145-
146132
// Enable the slide overview mode
147133
overview: {{ overview }},
148-
149134
// Vertical centering of slides
150135
center: {{ center }},
151-
152136
// Enables touch navigation on devices with touch input
153137
touch: {{ touch }},
154-
155138
// Loop the presentation
156139
loop: {{ loop }},
157-
158140
// Change the presentation direction to be RTL
159141
rtl: {{ rtl }},
160-
161142
// Changes the behavior of our navigation directions.
162143
//
163144
// "default"
@@ -183,138 +164,104 @@
183164
// from 1.3 -> 2.1. If "grid" is used, the same navigation takes you
184165
// from 1.3 -> 2.3.
185166
navigationMode: {{ navigation_mode }},
186-
187167
// Randomizes the order of slides each time the presentation loads
188168
shuffle: {{ shuffle }},
189-
190169
// Turns fragments on and off globally
191170
fragments: {{ fragments }},
192-
193171
// Flags whether to include the current fragment in the URL,
194172
// so that reloading brings you to the same fragment position
195173
fragmentInURL: {{ fragment_in_url }},
196-
197174
// Flags if the presentation is running in an embedded mode,
198175
// i.e. contained within a limited portion of the screen
199176
embedded: {{ embedded }},
200-
201177
// Flags if we should show a help overlay when the question-mark
202178
// key is pressed
203179
help: {{ help }},
204-
205180
// Flags if it should be possible to pause the presentation (blackout)
206181
pause: {{ pause }},
207-
208182
// Flags if speaker notes should be visible to all viewers
209183
showNotes: {{ show_notes }},
210-
211184
// Global override for autolaying embedded media (video/audio/iframe)
212185
// - null: Media will only autoplay if data-autoplay is present
213186
// - true: All media will autoplay, regardless of individual setting
214187
// - false: No media will autoplay, regardless of individual setting
215188
autoPlayMedia: {{ auto_play_media }},
216-
217189
// Global override for preloading lazy-loaded iframes
218190
// - null: Iframes with data-src AND data-preload will be loaded when within
219191
// the viewDistance, iframes with only data-src will be loaded when visible
220192
// - true: All iframes with data-src will be loaded when within the viewDistance
221193
// - false: All iframes with data-src will be loaded only when visible
222194
preloadIframes: {{ preload_iframes }},
223-
224195
// Can be used to globally disable auto-animation
225196
autoAnimate: {{ auto_animate }},
226-
227197
// Optionally provide a custom element matcher that will be
228198
// used to dictate which elements we can animate between.
229199
autoAnimateMatcher: {{ auto_animate_matcher }},
230-
231200
// Default settings for our auto-animate transitions, can be
232201
// overridden per-slide or per-element via data arguments
233202
autoAnimateEasing: {{ auto_animate_easing }},
234203
autoAnimateDuration: {{ auto_animate_duration }},
235204
autoAnimateUnmatched: {{ auto_animate_unmatched }},
236-
237205
// CSS properties that can be auto-animated. Position & scale
238206
// is matched separately so there's no need to include styles
239207
// like top/right/bottom/left, width/height or margin.
240208
autoAnimateStyles: {{ auto_animate_styles }},
241-
242209
// Controls automatic progression to the next slide
243210
// - 0: Auto-sliding only happens if the data-autoslide HTML attribute
244211
// is present on the current slide or fragment
245212
// - 1+: All slides will progress automatically at the given interval
246213
// - false: No auto-sliding, even if data-autoslide is present
247214
autoSlide: {{ auto_slide }},
248-
249215
// Stop auto-sliding after user input
250216
autoSlideStoppable: {{ auto_slide_stoppable }},
251-
252217
// Use this method for navigation when auto-sliding (defaults to navigateNext)
253218
autoSlideMethod: {{ auto_slide_method }},
254-
255219
// Specify the average time in seconds that you think you will spend
256220
// presenting each slide. This is used to show a pacing timer in the
257221
// speaker view
258222
defaultTiming: {{ default_timing }},
259-
260223
// Enable slide navigation via mouse wheel
261224
mouseWheel: {{ mouse_wheel }},
262-
263225
// Opens links in an iframe preview overlay
264226
// Add `data-preview-link` and `data-preview-link="false"` to customize each link
265227
// individually
266228
previewLinks: {{ preview_links }},
267-
268229
// Exposes the reveal.js API through window.postMessage
269230
postMessage: {{ post_message }},
270-
271231
// Dispatches all reveal.js events to the parent window through postMessage
272232
postMessageEvents: {{ post_message_events }},
273-
274233
// Focuses body when page changes visibility to ensure keyboard shortcuts work
275234
focusBodyOnPageVisibilityChange: {{ focus_body_on_page_visibility_change }},
276-
277235
// Transition style
278236
transition: {{ transition }}, // none/fade/slide/convex/concave/zoom
279-
280237
// Transition speed
281238
transitionSpeed: {{ transition_speed }}, // default/fast/slow
282-
283239
// Transition style for full page slide backgrounds
284240
backgroundTransition: {{ background_transition }}, // none/fade/slide/convex/concave/zoom
285-
286241
// The maximum number of pages a single slide can expand onto when printing
287242
// to PDF, unlimited by default
288243
pdfMaxPagesPerSlide: {{ pdf_max_pages_per_slide }},
289-
290244
// Prints each fragment on a separate slide
291245
pdfSeparateFragments: {{ pdf_separate_fragments }},
292-
293246
// Offset used to reduce the height of content within exported PDF pages.
294247
// This exists to account for environment differences based on how you
295248
// print to PDF. CLI printing options, like phantomjs and wkpdf, can end
296249
// on precisely the total height of the document whereas in-browser
297250
// printing has to end one pixel before.
298251
pdfPageHeightOffset: {{ pdf_page_height_offset }},
299-
300252
// Number of slides away from the current that are visible
301253
viewDistance: {{ view_distance }},
302-
303254
// Number of slides away from the current that are visible on mobile
304255
// devices. It is advisable to set this to a lower number than
305256
// viewDistance in order to save resources.
306257
mobileViewDistance: {{ mobile_view_distance }},
307-
308258
// The display mode that will be used to show slides
309259
display: {{ display }},
310-
311260
// Hide cursor if inactive
312261
hideInactiveCursor: {{ hide_inactive_cursor }},
313-
314262
// Time before the cursor is hidden (in ms)
315263
hideCursorTime: {{ hide_cursor_time }}
316264
});
317-
318265
{% if one_file %}
319266
// Fix found by @t-fritsch and @Rapsssito on GitHub
320267
// see: https://github.com/hakimel/reveal.js/discussions/3362#discussioncomment-11733074.

manim_slides/convert.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,9 @@ def prefix(i: int) -> str:
594594
dest.parent.mkdir(parents=True, exist_ok=True)
595595

596596
with open(dest, "w") as f:
597-
revealjs_template = Template(self.load_template())
597+
revealjs_template = Template(
598+
self.load_template(), trim_blocks=True, lstrip_blocks=True
599+
)
598600

599601
options = self.model_dump()
600602

0 commit comments

Comments
 (0)