git.iko.soy/typeable/pandoc
on master help sign in
reveal.js writer: better handling of options.

Previously it was impossible to specify false values for options that default to true; setting the option to false just caused the portion of the template setting the option to be omitted. Now we prepopulate all the variables with their default values, including them unconditionally and allowing them to be overridden.

commit14b2eb2aeb21b3dee7d07c7348ebd2c586d6a866 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 21 Jun 2021, 16:40 (5 years ago) parenta39313e
2 files changed+120−128
data/templates/default.revealjs+70−128 src/Text/Pandoc/Writers/HTML.hs+50
data/templates/default.revealjs+70−128
@@ -90,256 +90,198 @@ $endif$
9090 // Full list of configuration options available at:
9191 // https://revealjs.com/config/
9292 Reveal.initialize({
93−$if(center)$
94− // Determines whether slide content should be vertically centered
95− center: $center$,
96−$endif$
97−$if(controls)$
9893 // Display controls in the bottom right corner
9994 controls: $controls$,
100−$endif$
101−$if(controlsTutorial)$
95+
10296 // Help the user learn the controls by providing hints, for example by
10397 // bouncing the down arrow when they first encounter a vertical slide
10498 controlsTutorial: $controlsTutorial$,
105−$endif$
106−$if(controlsLayout)$
99+
107100 // Determines where controls appear, "edges" or "bottom-right"
108101 controlsLayout: '$controlsLayout$',
109−$endif$
110−$if(controlsBackArrows)$
102+
111103 // Visibility rule for backwards navigation arrows; "faded", "hidden"
112104 // or "visible"
113105 controlsBackArrows: '$controlsBackArrows$',
114−$endif$
115−$if(progress)$
106+
116107 // Display a presentation progress bar
117108 progress: $progress$,
118−$endif$
119−$if(slideNumber)$
109+
120110 // Display the page number of the current slide
121111 slideNumber: $slideNumber$,
122−$endif$
123−$if(showSlideNumber)$
112+
124113 // 'all', 'print', or 'speaker'
125114 showSlideNumber: '$showSlideNumber$',
126−$endif$
115+
127116 // Add the current slide number to the URL hash so that reloading the
128117 // page/copying the URL will return you to the same slide
129− hash: $if(hash)$$hash$$else$true$endif$,
130−$if(hashOneBasedIndex)$
118+ hash: $hash$,
119+
131120 // Start with 1 for the hash rather than 0
132121 hashOneBasedIndex: $hashOneBasedIndex$,
133−$endif$
134−$if(history)$
122+
123+ // Flags if we should monitor the hash and change slides accordingly
124+ respondToHashChanges: $respondToHashChanges$,
125+
135126 // Push each slide change to the browser history
136127 history: $history$,
137−$endif$
138−$if(keyboard)$
128+
139129 // Enable keyboard shortcuts for navigation
140130 keyboard: $keyboard$,
141−$endif$
142−$if(overview)$
131+
143132 // Enable the slide overview mode
144133 overview: $overview$,
145−$endif$
146−$if(center)$
134+
135+ // Disables the default reveal.js slide layout (scaling and centering)
136+ // so that you can use custom CSS layout
137+ disableLayout: false,
138+
147139 // Vertical centering of slides
148140 center: $center$,
149−$endif$
150−$if(touch)$
141+
151142 // Enables touch navigation on devices with touch input
152143 touch: $touch$,
153−$endif$
154−$if(loop)$
144+
155145 // Loop the presentation
156146 loop: $loop$,
157−$endif$
158−$if(rtl)$
147+
159148 // Change the presentation direction to be RTL
160149 rtl: $rtl$,
161−$endif$
162−$if(navigationMode)$
150+
163151 // see https://revealjs.com/vertical-slides/#navigation-mode
164152 navigationMode: '$navigationMode$',
165−$endif$
166−$if(shuffle)$
153+
167154 // Randomizes the order of slides each time the presentation loads
168155 shuffle: $shuffle$,
169−$endif$
170−$if(fragments)$
156+
171157 // Turns fragments on and off globally
172158 fragments: $fragments$,
173−$endif$
174−$if(fragmentInURL)$
159+
175160 // Flags whether to include the current fragment in the URL,
176161 // so that reloading brings you to the same fragment position
177162 fragmentInURL: $fragmentInURL$,
178−$endif$
179−$if(embedded)$
163+
180164 // Flags if the presentation is running in an embedded mode,
181165 // i.e. contained within a limited portion of the screen
182166 embedded: $embedded$,
183−$endif$
184−$if(help)$
167+
185168 // Flags if we should show a help overlay when the questionmark
186169 // key is pressed
187170 help: $help$,
188−$endif$
189−$if(pause)$
190− // Flags if it should be possible to pause the presentation (blackout)
191− pause: $pause$,
192−$endif$
193−$if(showNotes)$
171+
172+ // Flags if it should be possible to pause the presentation (blackout)
173+ pause: $pause$,
174+
194175 // Flags if speaker notes should be visible to all viewers
195176 showNotes: $showNotes$,
196−$endif$
197−$if(autoPlayMedia)$
198− // Global override for autoplaying embedded media (video/audio/iframe)
199− // - null: Media will only autoplay if data-autoplay is present
200− // - true: All media will autoplay, regardless of individual setting
201− // - false: No media will autoplay, regardless of individual setting
177+
178+ // Global override for autoplaying embedded media (null/true/false)
202179 autoPlayMedia: $autoPlayMedia$,
203−$endif$
204−$if(preloadIframes)$
205− // Global override for preloading lazy-loaded iframes
206− // - null: Iframes with data-src AND data-preload will be loaded when within
207− // the viewDistance, iframes with only data-src will be loaded when visible
208− // - true: All iframes with data-src will be loaded when within the viewDistance
209− // - false: All iframes with data-src will be loaded only when visible
180+
181+ // Global override for preloading lazy-loaded iframes (null/true/false)
210182 preloadIframes: $preloadIframes$,
211−$endif$
212−$if(autoSlide)$
183+
213184 // Number of milliseconds between automatically proceeding to the
214185 // next slide, disabled when set to 0, this value can be overwritten
215186 // by using a data-autoslide attribute on your slides
216187 autoSlide: $autoSlide$,
217−$endif$
218−$if(autoSlideStoppable)$
188+
219189 // Stop auto-sliding after user input
220190 autoSlideStoppable: $autoSlideStoppable$,
221−$endif$
222−$if(autoSlideMethod)$
191+
223192 // Use this method for navigation when auto-sliding
224193 autoSlideMethod: $autoSlideMethod$,
225−$endif$
226−$if(defaultTiming)$
194+
227195 // Specify the average time in seconds that you think you will spend
228196 // presenting each slide. This is used to show a pacing timer in the
229197 // speaker view
230198 defaultTiming: $defaultTiming$,
231−$endif$
232−$if(totalTime)$
233− // Specify the total time in seconds that is available to
234− // present. If this is set to a nonzero value, the pacing
235− // timer will work out the time available for each slide,
236− // instead of using the defaultTiming value
237− totalTime: $totalTime$,
238−$endif$
239−$if(minimumTimePerSlide)$
240− // Specify the minimum amount of time you want to allot to
241− // each slide, if using the totalTime calculation method. If
242− // the automated time allocation causes slide pacing to fall
243− // below this threshold, then you will see an alert in the
244− // speaker notes window
245− minimumTimePerSlide: $minimumTimePerSlide$,
246−$endif$
247−$if(mouseWheel)$
199+
248200 // Enable slide navigation via mouse wheel
249201 mouseWheel: $mouseWheel$,
250−$endif$
251−$if(rollingLinks)$
252− // Apply a 3D roll to links on hover
253− rollingLinks: $rollingLinks$,
254−$endif$
255−$if(hideInactiveCursor)$
202+
203+ // The display mode that will be used to show slides
204+ display: '$display$',
205+
256206 // Hide cursor if inactive
257207 hideInactiveCursor: $hideInactiveCursor$,
258−$endif$
259−$if(hideCursorTime)$
208+
260209 // Time before the cursor is hidden (in ms)
261210 hideCursorTime: $hideCursorTime$,
262−$endif$
263−$if(hideAddressBar)$
264− // Hides the address bar on mobile devices
265− hideAddressBar: $hideAddressBar$,
266−$endif$
267−$if(previewLinks)$
211+
268212 // Opens links in an iframe preview overlay
269213 previewLinks: $previewLinks$,
270−$endif$
271−$if(transition)$
272− // Transition style
273− transition: '$transition$', // none/fade/slide/convex/concave/zoom
274−$endif$
275−$if(transitionSpeed)$
276− // Transition speed
277− transitionSpeed: '$transitionSpeed$', // default/fast/slow
278−$endif$
279−$if(backgroundTransition)$
214+
215+ // Transition style (none/fade/slide/convex/concave/zoom)
216+ transition: '$transition$',
217+
218+ // Transition speed (default/fast/slow)
219+ transitionSpeed: '$transitionSpeed$',
220+
280221 // Transition style for full page slide backgrounds
281− backgroundTransition: '$backgroundTransition$', // none/fade/slide/convex/concave/zoom
282−$endif$
283−$if(viewDistance)$
222+ // (none/fade/slide/convex/concave/zoom)
223+ backgroundTransition: '$backgroundTransition$',
224+
284225 // Number of slides away from the current that are visible
285226 viewDistance: $viewDistance$,
286−$endif$
287−$if(mobileViewDistance)$
227+
288228 // Number of slides away from the current that are visible on mobile
289229 // devices. It is advisable to set this to a lower number than
290230 // viewDistance in order to save resources.
291231 mobileViewDistance: $mobileViewDistance$,
292−$endif$
293232$if(parallaxBackgroundImage)$
233+
294234 // Parallax background image
295235 parallaxBackgroundImage: '$parallaxBackgroundImage$', // e.g. "'https://s3.amazonaws.com/hakim-static/reveal-js/reveal-parallax-1.jpg'"
296236$else$
297237$if(background-image)$
238+
298239 // Parallax background image
299240 parallaxBackgroundImage: '$background-image$', // e.g. "'https://s3.amazonaws.com/hakim-static/reveal-js/reveal-parallax-1.jpg'"
300241$endif$
301242$endif$
302243$if(parallaxBackgroundSize)$
244+
303245 // Parallax background size
304246 parallaxBackgroundSize: '$parallaxBackgroundSize$', // CSS syntax, e.g. "2100px 900px"
305247$endif$
306248$if(parallaxBackgroundHorizontal)$
249+
307250 // Amount to move parallax background (horizontal and vertical) on slide change
308251 // Number, e.g. 100
309252 parallaxBackgroundHorizontal: $parallaxBackgroundHorizontal$,
310253$endif$
311254$if(parallaxBackgroundVertical)$
255+
312256 parallaxBackgroundVertical: $parallaxBackgroundVertical$,
313257$endif$
314258$if(width)$
259+
315260 // The "normal" size of the presentation, aspect ratio will be preserved
316261 // when the presentation is scaled to fit different resolutions. Can be
317262 // specified using percentage units.
318263 width: $width$,
319264$endif$
320265$if(height)$
266+
321267 height: $height$,
322268$endif$
323269$if(margin)$
270+
324271 // Factor of the display size that should remain empty around the content
325272 margin: $margin$,
326273$endif$
327274$if(minScale)$
275+
328276 // Bounds for smallest/largest possible scale to apply to content
329277 minScale: $minScale$,
330278$endif$
331279$if(maxScale)$
280+
332281 maxScale: $maxScale$,
333282$endif$
334−$if(zoomKey)$
335− // Modifier key used to click-zoom to part of the slide
336− zoomKey: '$zoomKey$',
337−$endif$
338−$if(display)$
339− // The display mode that will be used to show slides
340− display: '$display$',
341−$endif$
342283$if(mathjax)$
284+
343285 math: {
344286 mathjax: '$mathjaxurl$',
345287 config: 'TeX-AMS_HTML-full',
src/Text/Pandoc/Writers/HTML.hs+50
@@ -317,6 +317,10 @@ pandocToHtml opts (Pandoc meta blocks) = do
317317 | otherwise -> mempty
318318 Nothing -> mempty
319319 let mCss :: Maybe [Text] = lookupContext "css" metadata
320+ let true :: Text
321+ true = "true"
322+ let false :: Text
323+ false = "false"
320324 let context = (if stHighlighting st
321325 then case writerHighlightStyle opts of
322326 Just sty -> defField "highlighting-css"
@@ -344,6 +348,52 @@ pandocToHtml opts (Pandoc meta blocks) = do
344348 PlainMath -> defField "displaymath-css" True
345349 WebTeX _ -> defField "displaymath-css" True
346350 _ -> id) .
351+ (if slideVariant == RevealJsSlides
352+ then -- set boolean options explicitly, since
353+ -- template can't distinguish False/undefined
354+ defField "controls" true .
355+ defField "controlsTutorial" true .
356+ defField "controlsLayout" ("bottom-right" :: Text) .
357+ defField "controlsBackArrows" ("faded" :: Text) .
358+ defField "progress" true .
359+ defField "slideNumber" false .
360+ defField "showSlideNumber" ("all" :: Text) .
361+ defField "hashOneBasedIndex" false .
362+ defField "hash" false .
363+ defField "respondToHashChanges" true .
364+ defField "history" false .
365+ defField "keyboard" true .
366+ defField "overview" true .
367+ defField "disableLayout" false .
368+ defField "center" true .
369+ defField "touch" true .
370+ defField "loop" false .
371+ defField "rtl" false .
372+ defField "navigationMode" ("default" :: Text) .
373+ defField "shuffle" false .
374+ defField "fragments" true .
375+ defField "fragmentInURL" true .
376+ defField "embedded" false .
377+ defField "help" true .
378+ defField "pause" true .
379+ defField "showNotes" false .
380+ defField "autoPlayMedia" ("null" :: Text) .
381+ defField "preloadIframes" ("null" :: Text) .
382+ defField "autoSlide" ("0" :: Text) .
383+ defField "autoSlideStoppable" true .
384+ defField "autoSlideMethod" ("null" :: Text) .
385+ defField "defaultTiming" ("null" :: Text) .
386+ defField "mouseWheel" false .
387+ defField "display" ("block" :: Text) .
388+ defField "hideInactiveCursor" true .
389+ defField "hideCursorTime" ("5000" :: Text) .
390+ defField "previewLinks" false .
391+ defField "transition" ("slide" :: Text) .
392+ defField "transitionSpeed" ("default" :: Text) .
393+ defField "backgroundTransition" ("fade" :: Text) .
394+ defField "viewDistance" ("3" :: Text) .
395+ defField "mobileViewDistance" ("2" :: Text)
396+ else id) .
347397 defField "document-css" (isNothing mCss && slideVariant == NoSlides) .
348398 defField "quotes" (stQuotes st) .
349399 -- for backwards compatibility we populate toc