git.iko.soy/typeable/pandoc
on master help sign in
Added --slide-level option to override default.

This allows users to select a slide level below the first header level with content. Note that content under sections above the slide level will not appear in slides (either in beamer or in HTML slide shows). This is primarily useful for creating documents that can be made into both slides and handouts (which contain additional content outside the slides).

commit60bf741d689700554ca971dc87417f05a32e3981 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 25 Jan 2012, 17:50 (15 years ago) parent2c4a55d
6 files changed+53−13
README+21−8 src/Text/Pandoc/Shared.hs+2 src/Text/Pandoc/Writers/HTML.hs+9−3 src/Text/Pandoc/Writers/LaTeX.hs+5−1 src/pandoc.hs+15 templates+1−1
README+21−8
@@ -306,6 +306,15 @@ Options
306306: Produce LaTeX output for the `beamer` document class.
307307 This has an effect only for `latex` or `pdf` output.
308308
309+`--slide-level`=*NUMBER*
310+: Specifies that headers with the specified level create
311+ slides (for `beamer`, `s5`, `slidy`, `dzslides`). Headers
312+ above this level in the hierarchy are used to divide the
313+ slide show into sections; headers below this level create
314+ subheads within a slide. The default is to set the slide level
315+ based on the contents of the document; see
316+ [Structuring the slide show](#structuring-the-slide-show), below.
317+
309318`--section-divs`
310319: Wrap sections in `<div>` tags (or `<section>` tags in HTML5),
311320 and attach identifiers to the enclosing `<div>` (or `<section>`)
@@ -2006,20 +2015,24 @@ slide show, including linked scripts, stylesheets, images, and videos.
20062015Structuring the slide show
20072016--------------------------
20082017
2018+By default, the *slide level* is the highest header level in
2019+the hierarchy that is followed immediately by content, and not another
2020+header, somewhere in the document. In the example above, level 1 headers
2021+are always followed by level 2 headers, which are followed by content,
2022+so 2 is the slide level. This default can be overridden using
2023+the `--slide-level` option.
2024+
20092025The document is carved up into slides according to the following
2010−rules. The *content level* is the the highest header level in the hierarchy
2011−that is followed immediately by content, and not another header, somewhere in
2012−the document. In the example above, level 1 headers are always followed by
2013−level 2 headers, which are followed by content, so 2 is the content level.
2026+rules:
20142027
20152028 * A horizontal rule always starts a new slide.
20162029
2017− * A header at the content level always starts a new slide.
2030+ * A header at the slide level always starts a new slide.
20182031
2019− * Headers *below* the content level in the hierarchy create
2032+ * Headers *below* the slide level in the hierarchy create
20202033 headers *within* a slide.
20212034
2022− * Headers *above* the content level in the hierarchy create
2035+ * Headers *above* the slide level in the hierarchy create
20232036 "title slides," which just contain the section title
20242037 and help to break the slide show into sections.
20252038
@@ -2030,7 +2043,7 @@ level 2 headers, which are followed by content, so 2 is the content level.
20302043These rules are designed to support many different styles of slide show. If
20312044you don't care about structuring your slides into sections and subsections,
20322045you can just use level 1 headers for all each slide. (In that case, level 1
2033−will be the content level.) But you can also structure the slide show into
2046+will be the slide level.) But you can also structure the slide show into
20342047sections, as in the example above.
20352048
20362049For Slidy and S5, the file produced by pandoc with the `-s/--standalone`
src/Text/Pandoc/Shared.hs+2
@@ -478,6 +478,7 @@ data WriterOptions = WriterOptions
478478 , writerBiblioFiles :: [FilePath] -- ^ Biblio files to use for citations
479479 , writerHtml5 :: Bool -- ^ Produce HTML5
480480 , writerBeamer :: Bool -- ^ Produce beamer LaTeX slide show
481+ , writerSlideLevel :: Maybe Int -- ^ Force header level of slides
481482 , writerChapters :: Bool -- ^ Use "chapter" for top-level sects
482483 , writerListings :: Bool -- ^ Use listings package for code
483484 , writerHighlight :: Bool -- ^ Highlight source code
@@ -514,6 +515,7 @@ defaultWriterOptions =
514515 , writerBiblioFiles = []
515516 , writerHtml5 = False
516517 , writerBeamer = False
518+ , writerSlideLevel = Nothing
517519 , writerChapters = False
518520 , writerListings = False
519521 , writerHighlight = False
src/Text/Pandoc/Writers/HTML.hs+9−3
@@ -115,7 +115,7 @@ pandocToHtml opts (Pandoc (Meta title' authors' date') blocks) = do
115115 date <- if standalone
116116 then inlineListToHtml opts date'
117117 else return mempty
118− let slideLevel = getSlideLevel blocks
118+ let slideLevel = maybe (getSlideLevel blocks) id $ writerSlideLevel opts
119119 let sects = hierarchicalize $
120120 if writerSlideVariant opts == NoSlides
121121 then blocks
@@ -252,15 +252,21 @@ elementToHtml slideLevel opts (Sec level num id' title' elements) = do
252252 modify $ \st -> st{stSecNum = num} -- update section number
253253 -- always use level 1 for slide titles
254254 let level' = if slide then 1 else level
255+ let titleSlide = slide && level < slideLevel
255256 header' <- blockToHtml opts (Header level' title')
256− innerContents <- mapM (elementToHtml slideLevel opts) elements
257+ let isSec (Sec _ _ _ _ _) = True
258+ isSec (Blk _) = False
259+ innerContents <- mapM (elementToHtml slideLevel opts)
260+ $ if titleSlide
261+ -- title slides have no content of their own
262+ then filter isSec elements
263+ else elements
257264 let header'' = if (writerStrictMarkdown opts ||
258265 writerSectionDivs opts ||
259266 writerSlideVariant opts == S5Slides)
260267 then header'
261268 else header' ! prefixedId opts id'
262269 let inNl x = mconcat $ nl opts : intersperse (nl opts) x ++ [nl opts]
263− let titleSlide = slide && level < slideLevel
264270 let classes = ["titleslide" | titleSlide] ++ ["slide" | slide] ++
265271 ["level" ++ show level]
266272 let secttag = if writerHtml5 opts
src/Text/Pandoc/Writers/LaTeX.hs+5−1
@@ -201,7 +201,8 @@ inCmd cmd contents = char '\\' <> text cmd <> braces contents
201201
202202toSlides :: [Block] -> State WriterState [Block]
203203toSlides bs = do
204− let slideLevel = getSlideLevel bs
204+ opts <- gets stOptions
205+ let slideLevel = maybe (getSlideLevel bs) id $ writerSlideLevel opts
205206 let bs' = prepSlides slideLevel bs
206207 concat `fmap` (mapM (elementToBeamer slideLevel) $ hierarchicalize bs')
207208
@@ -214,7 +215,10 @@ elementToBeamer slideLevel (Sec lvl _num _ident tit elts)
214215 : tit ++ [RawInline "latex" "}"] )
215216 : bs ++ [RawBlock "latex" "\\end{block}"]
216217 | lvl < slideLevel = do
218+ let isSec (Sec _ _ _ _ _) = True
219+ isSec (Blk _) = False
217220 bs <- concat `fmap` mapM (elementToBeamer slideLevel) elts
221+ -- (filter isSec elts)
218222 return $ (Header lvl tit) : bs
219223 | otherwise = do -- lvl == slideLevel
220224 -- note: [fragile] is required or verbatim breaks
src/pandoc.hs+15
@@ -131,6 +131,7 @@ data Opt = Opt
131131 , optListings :: Bool -- ^ Use listings package for code blocks
132132 , optLaTeXEngine :: String -- ^ Program to use for latex -> pdf
133133 , optBeamer :: Bool -- ^ Produce latex output for beamer class
134+ , optSlideLevel :: Maybe Int -- ^ Header level that creates slides
134135 }
135136
136137-- | Defaults for command-line options.
@@ -180,6 +181,7 @@ defaultOpts = Opt
180181 , optListings = False
181182 , optLaTeXEngine = "pdflatex"
182183 , optBeamer = False
184+ , optSlideLevel = Nothing
183185 }
184186
185187-- | A list of functions, each transforming the options data structure
@@ -381,6 +383,17 @@ options =
381383 (\opt -> return opt { optBeamer = True }))
382384 "" -- "Produce latex output for beamer class"
383385
386+ , Option "" ["slide-level"]
387+ (ReqArg
388+ (\arg opt -> do
389+ case reads arg of
390+ [(t,"")] | t >= 1 && t <= 6 ->
391+ return opt { optSlideLevel = Just t }
392+ _ -> err 39 $
393+ "slide level must be a number between 1 and 6")
394+ "NUMBER")
395+ "" -- "Force header level for slides"
396+
384397 , Option "" ["section-divs"]
385398 (NoArg
386399 (\opt -> return opt { optSectionDivs = True }))
@@ -795,6 +808,7 @@ main = do
795808 , optListings = listings
796809 , optLaTeXEngine = latexEngine
797810 , optBeamer = beamer
811+ , optSlideLevel = slideLevel
798812 } = opts
799813
800814 when dumpArgs $
@@ -943,6 +957,7 @@ main = do
943957 writerChapters = chapters,
944958 writerListings = listings,
945959 writerBeamer = beamer,
960+ writerSlideLevel = slideLevel,
946961 writerHighlight = highlight,
947962 writerHighlightStyle = highlightStyle }
948963
templates+1−1

Submodule changed.