git.iko.soy/typeable/pandoc
on master help sign in
Simplified slide creation in HTML writer.
072df3fJohn MacFarlane
src/Text/Pandoc/Writers/HTML.hs+18−26
@@ -106,18 +106,17 @@ pandocToHtml opts (Pandoc (Meta title' authors' date') blocks) = do
106 date <- if standalone
106 date <- if standalone
107 then inlineListToHtml opts date'
107 then inlineListToHtml opts date'
108 else return noHtml
108 else return noHtml
109+ let splitHrule (HorizontalRule : Header 1 xs : ys)
110+ = Header 1 xs : splitHrule ys
111+ splitHrule (HorizontalRule : xs) = Header 1 [] : splitHrule xs
112+ splitHrule (x : xs) = x : splitHrule xs
113+ splitHrule [] = []
114+ let ensureStartWithH1 bs@(Header 1 _:_) = bs
115+ ensureStartWithH1 bs = Header 1 [] : bs
109 let sects = hierarchicalize $
116 let sects = hierarchicalize $
110 if writerSlideVariant opts == NoSlides
117 if writerSlideVariant opts == NoSlides
111 then blocks
118 then blocks
112− else case blocks of
119+ else ensureStartWithH1 $ splitHrule blocks
113− (Header 1 _ : _) -> blocks
114− _ ->
115− let isL1 (Header 1 _) = True
116− isL1 _ = False
117− (preBlocks, rest) = break isL1 blocks
118− in (RawBlock "html" "<div class=\"slide\">" :
119− preBlocks) ++ (RawBlock "html" "</div>" :
120− rest)
121 toc <- if writerTableOfContents opts
120 toc <- if writerTableOfContents opts
122 then tableOfContents opts sects
121 then tableOfContents opts sects
123 else return Nothing
122 else return Nothing
@@ -226,13 +225,6 @@ elementToListItem opts (Sec _ num id' headerText subsecs) = do
226
225
227-- | Convert an Element to Html.
226-- | Convert an Element to Html.
228elementToHtml :: WriterOptions -> Element -> State WriterState Html
227elementToHtml :: WriterOptions -> Element -> State WriterState Html
229−elementToHtml opts (Blk HorizontalRule)
230− | writerSlideVariant opts == S5Slides ||
231− writerSlideVariant opts == SlidySlides =
232− return $ primHtml "</div>" +++ nl opts +++ primHtml "<div class=\"slide\">"
233−elementToHtml opts (Blk HorizontalRule)
234− | writerSlideVariant opts == DZSlides =
235− return $ primHtml "</section>" +++ nl opts +++ primHtml "<section>"
236elementToHtml opts (Blk block) = blockToHtml opts block
228elementToHtml opts (Blk block) = blockToHtml opts block
237elementToHtml opts (Sec level num id' title' elements) = do
229elementToHtml opts (Sec level num id' title' elements) = do
238 modify $ \st -> st{stSecNum = num} -- update section number
230 modify $ \st -> st{stSecNum = num} -- update section number
@@ -244,17 +236,17 @@ elementToHtml opts (Sec level num id' title' elements) = do
244 writerSlideVariant opts == S5Slides)]
236 writerSlideVariant opts == S5Slides)]
245 let stuff = header'' : innerContents
237 let stuff = header'' : innerContents
246 let slide = writerSlideVariant opts /= NoSlides && level == 1
238 let slide = writerSlideVariant opts /= NoSlides && level == 1
247− let stuff' = if (writerSlideVariant opts == S5Slides ||
239+ let titleSlide = slide && null elements
248− writerSlideVariant opts == SlidySlides) && level == 1
240+ let classes = [theclass "titleslide" | titleSlide] ++
249− then [thediv ! [theclass "slide"] <<
241+ [theclass "slide" | slide]
250− (nl opts : intersperse (nl opts) stuff ++ [nl opts])]
251− else intersperse (nl opts) stuff
252− let inNl x = nl opts : x ++ [nl opts]
242+ let inNl x = nl opts : intersperse (nl opts) x ++ [nl opts]
253− return $ if writerSectionDivs opts || writerSlideVariant opts == DZSlides
243+ return $ if writerSectionDivs opts || slide
254 then if writerHtml5 opts
244 then if writerHtml5 opts
255− then tag "section" ! [prefixedId opts id'] << inNl stuff'
245+ then tag "section" ! (prefixedId opts id' : classes)
246+ << inNl stuff
256− else thediv ! [prefixedId opts id'] << inNl stuff'
247+ else thediv ! (prefixedId opts id' : classes)
248+ << inNl stuff
257− else toHtmlFromList stuff'
249+ else toHtmlFromList $ intersperse (nl opts) stuff
258
250
259-- | Convert list of Note blocks to a footnote <div>.
251-- | Convert list of Note blocks to a footnote <div>.
260-- Assumes notes are sorted.
252-- Assumes notes are sorted.
tests/s5.basic.html+2−2
@@ -34,14 +34,14 @@
34 <h3>Sam Smith<br/>Jen Jones</h3>
34 <h3>Sam Smith<br/>Jen Jones</h3>
35 <h4>July 15, 2006</h4>
35 <h4>July 15, 2006</h4>
36</div>
36</div>
37−<div class="slide">
37+<div id="first-slide" class="slide">
38<h1>First slide</h1>
38<h1>First slide</h1>
39<ul>
39<ul>
40<li>first bullet</li>
40<li>first bullet</li>
41<li>second bullet</li>
41<li>second bullet</li>
42</ul>
42</ul>
43</div>
43</div>
44−<div class="slide">
44+<div id="math" class="slide">
45<h1>Math</h1>
45<h1>Math</h1>
46<ul>
46<ul>
47<li><span class="math">$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</span></li>
47<li><span class="math">$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</span></li>
tests/s5.fancy.html+2−2
@@ -235,14 +235,14 @@
235 <h3>Sam Smith<br/>Jen Jones</h3>
235 <h3>Sam Smith<br/>Jen Jones</h3>
236 <h4>July 15, 2006</h4>
236 <h4>July 15, 2006</h4>
237</div>
237</div>
238−<div class="slide">
238+<div id="first-slide" class="slide">
239<h1>First slide</h1>
239<h1>First slide</h1>
240<ul class="incremental">
240<ul class="incremental">
241<li>first bullet</li>
241<li>first bullet</li>
242<li>second bullet</li>
242<li>second bullet</li>
243</ul>
243</ul>
244</div>
244</div>
245−<div class="slide">
245+<div id="math" class="slide">
246<h1>Math</h1>
246<h1>Math</h1>
247<ul class="incremental">
247<ul class="incremental">
248<li><span class="LaTeX">$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</span></li>
248<li><span class="LaTeX">$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</span></li>