git.iko.soy/typeable/pandoc
on master help sign in
Simplified slide creation in HTML writer.

A horizontal rule now gets transformed into an empty H1 header before 'hierarchicalize' is called. If the document that does not begin with an H1 header, an empty one is provided. This avoids the need for kludgy raw HTML. Also, the 'titleslide' class is added to any section containing just a title: ---- ----

commit072df3f5dd51589262467ba2d68bd3974b0f9277 authorJohn MacFarlane <fiddlosopher@gmail.com> dateSun 2 Oct 2011, 11:49 (15 years ago) parentc8f0bd7
3 files changed+22−30
src/Text/Pandoc/Writers/HTML.hs+18−26 tests/s5.basic.html+2−2 tests/s5.fancy.html+2−2
src/Text/Pandoc/Writers/HTML.hs+18−26
@@ -106,18 +106,17 @@ pandocToHtml opts (Pandoc (Meta title' authors' date') blocks) = do
106106 date <- if standalone
107107 then inlineListToHtml opts date'
108108 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
109116 let sects = hierarchicalize $
110117 if writerSlideVariant opts == NoSlides
111118 then blocks
112− else case blocks of
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)
119+ else ensureStartWithH1 $ splitHrule blocks
121120 toc <- if writerTableOfContents opts
122121 then tableOfContents opts sects
123122 else return Nothing
@@ -226,13 +225,6 @@ elementToListItem opts (Sec _ num id' headerText subsecs) = do
226225
227226-- | Convert an Element to Html.
228227elementToHtml :: 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>"
236228elementToHtml opts (Blk block) = blockToHtml opts block
237229elementToHtml opts (Sec level num id' title' elements) = do
238230 modify $ \st -> st{stSecNum = num} -- update section number
@@ -244,17 +236,17 @@ elementToHtml opts (Sec level num id' title' elements) = do
244236 writerSlideVariant opts == S5Slides)]
245237 let stuff = header'' : innerContents
246238 let slide = writerSlideVariant opts /= NoSlides && level == 1
247− let stuff' = if (writerSlideVariant opts == S5Slides ||
248− writerSlideVariant opts == SlidySlides) && level == 1
249− then [thediv ! [theclass "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]
253− return $ if writerSectionDivs opts || writerSlideVariant opts == DZSlides
239+ let titleSlide = slide && null elements
240+ let classes = [theclass "titleslide" | titleSlide] ++
241+ [theclass "slide" | slide]
242+ let inNl x = nl opts : intersperse (nl opts) x ++ [nl opts]
243+ return $ if writerSectionDivs opts || slide
254244 then if writerHtml5 opts
255− then tag "section" ! [prefixedId opts id'] << inNl stuff'
256− else thediv ! [prefixedId opts id'] << inNl stuff'
257− else toHtmlFromList stuff'
245+ then tag "section" ! (prefixedId opts id' : classes)
246+ << inNl stuff
247+ else thediv ! (prefixedId opts id' : classes)
248+ << inNl stuff
249+ else toHtmlFromList $ intersperse (nl opts) stuff
258250
259251-- | Convert list of Note blocks to a footnote <div>.
260252-- Assumes notes are sorted.
tests/s5.basic.html+2−2
@@ -34,14 +34,14 @@
3434 <h3>Sam Smith<br/>Jen Jones</h3>
3535 <h4>July 15, 2006</h4>
3636</div>
37−<div class="slide">
37+<div id="first-slide" class="slide">
3838<h1>First slide</h1>
3939<ul>
4040<li>first bullet</li>
4141<li>second bullet</li>
4242</ul>
4343</div>
44−<div class="slide">
44+<div id="math" class="slide">
4545<h1>Math</h1>
4646<ul>
4747<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 @@
235235 <h3>Sam Smith<br/>Jen Jones</h3>
236236 <h4>July 15, 2006</h4>
237237</div>
238−<div class="slide">
238+<div id="first-slide" class="slide">
239239<h1>First slide</h1>
240240<ul class="incremental">
241241<li>first bullet</li>
242242<li>second bullet</li>
243243</ul>
244244</div>
245−<div class="slide">
245+<div id="math" class="slide">
246246<h1>Math</h1>
247247<ul class="incremental">
248248<li><span class="LaTeX">$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</span></li>