git.iko.soy/typeable/pandoc
on master help sign in
Added --slide-level option to override default.
60bf741John MacFarlane
README+21−8
@@ -306,6 +306,15 @@ Options
306: Produce LaTeX output for the `beamer` document class.
306: Produce LaTeX output for the `beamer` document class.
307 This has an effect only for `latex` or `pdf` output.
307 This has an effect only for `latex` or `pdf` output.
308
308
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+
309`--section-divs`
318`--section-divs`
310: Wrap sections in `<div>` tags (or `<section>` tags in HTML5),
319: Wrap sections in `<div>` tags (or `<section>` tags in HTML5),
311 and attach identifiers to the enclosing `<div>` (or `<section>`)
320 and attach identifiers to the enclosing `<div>` (or `<section>`)
@@ -2006,20 +2015,24 @@ slide show, including linked scripts, stylesheets, images, and videos.
2006Structuring the slide show
2015Structuring the slide show
2007--------------------------
2016--------------------------
2008
2017
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+
2009The document is carved up into slides according to the following
2025The document is carved up into slides according to the following
2010−rules. The *content level* is the the highest header level in the hierarchy
2026+rules:
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.
2014
2027
2015 * A horizontal rule always starts a new slide.
2028 * A horizontal rule always starts a new slide.
2016
2029
2017− * A header at the content level always starts a new slide.
2030+ * A header at the slide level always starts a new slide.
2018
2031
2019− * Headers *below* the content level in the hierarchy create
2032+ * Headers *below* the slide level in the hierarchy create
2020 headers *within* a slide.
2033 headers *within* a slide.
2021
2034
2022− * Headers *above* the content level in the hierarchy create
2035+ * Headers *above* the slide level in the hierarchy create
2023 "title slides," which just contain the section title
2036 "title slides," which just contain the section title
2024 and help to break the slide show into sections.
2037 and help to break the slide show into sections.
2025
2038
@@ -2030,7 +2043,7 @@ level 2 headers, which are followed by content, so 2 is the content level.
2030These rules are designed to support many different styles of slide show. If
2043These rules are designed to support many different styles of slide show. If
2031you don't care about structuring your slides into sections and subsections,
2044you don't care about structuring your slides into sections and subsections,
2032you can just use level 1 headers for all each slide. (In that case, level 1
2045you 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
2034sections, as in the example above.
2047sections, as in the example above.
2035
2048
2036For Slidy and S5, the file produced by pandoc with the `-s/--standalone`
2049For 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
478 , writerBiblioFiles :: [FilePath] -- ^ Biblio files to use for citations
478 , writerBiblioFiles :: [FilePath] -- ^ Biblio files to use for citations
479 , writerHtml5 :: Bool -- ^ Produce HTML5
479 , writerHtml5 :: Bool -- ^ Produce HTML5
480 , writerBeamer :: Bool -- ^ Produce beamer LaTeX slide show
480 , writerBeamer :: Bool -- ^ Produce beamer LaTeX slide show
481+ , writerSlideLevel :: Maybe Int -- ^ Force header level of slides
481 , writerChapters :: Bool -- ^ Use "chapter" for top-level sects
482 , writerChapters :: Bool -- ^ Use "chapter" for top-level sects
482 , writerListings :: Bool -- ^ Use listings package for code
483 , writerListings :: Bool -- ^ Use listings package for code
483 , writerHighlight :: Bool -- ^ Highlight source code
484 , writerHighlight :: Bool -- ^ Highlight source code
@@ -514,6 +515,7 @@ defaultWriterOptions =
514 , writerBiblioFiles = []
515 , writerBiblioFiles = []
515 , writerHtml5 = False
516 , writerHtml5 = False
516 , writerBeamer = False
517 , writerBeamer = False
518+ , writerSlideLevel = Nothing
517 , writerChapters = False
519 , writerChapters = False
518 , writerListings = False
520 , writerListings = False
519 , writerHighlight = False
521 , writerHighlight = False
src/Text/Pandoc/Writers/HTML.hs+9−3
@@ -115,7 +115,7 @@ pandocToHtml opts (Pandoc (Meta title' authors' date') blocks) = do
115 date <- if standalone
115 date <- if standalone
116 then inlineListToHtml opts date'
116 then inlineListToHtml opts date'
117 else return mempty
117 else return mempty
118− let slideLevel = getSlideLevel blocks
118+ let slideLevel = maybe (getSlideLevel blocks) id $ writerSlideLevel opts
119 let sects = hierarchicalize $
119 let sects = hierarchicalize $
120 if writerSlideVariant opts == NoSlides
120 if writerSlideVariant opts == NoSlides
121 then blocks
121 then blocks
@@ -252,15 +252,21 @@ elementToHtml slideLevel opts (Sec level num id' title' elements) = do
252 modify $ \st -> st{stSecNum = num} -- update section number
252 modify $ \st -> st{stSecNum = num} -- update section number
253 -- always use level 1 for slide titles
253 -- always use level 1 for slide titles
254 let level' = if slide then 1 else level
254 let level' = if slide then 1 else level
255+ let titleSlide = slide && level < slideLevel
255 header' <- blockToHtml opts (Header level' title')
256 header' <- blockToHtml opts (Header level' title')
257+ let isSec (Sec _ _ _ _ _) = True
258+ isSec (Blk _) = False
256− innerContents <- mapM (elementToHtml slideLevel opts) elements
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
257 let header'' = if (writerStrictMarkdown opts ||
264 let header'' = if (writerStrictMarkdown opts ||
258 writerSectionDivs opts ||
265 writerSectionDivs opts ||
259 writerSlideVariant opts == S5Slides)
266 writerSlideVariant opts == S5Slides)
260 then header'
267 then header'
261 else header' ! prefixedId opts id'
268 else header' ! prefixedId opts id'
262 let inNl x = mconcat $ nl opts : intersperse (nl opts) x ++ [nl opts]
269 let inNl x = mconcat $ nl opts : intersperse (nl opts) x ++ [nl opts]
263− let titleSlide = slide && level < slideLevel
264 let classes = ["titleslide" | titleSlide] ++ ["slide" | slide] ++
270 let classes = ["titleslide" | titleSlide] ++ ["slide" | slide] ++
265 ["level" ++ show level]
271 ["level" ++ show level]
266 let secttag = if writerHtml5 opts
272 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
201
201
202toSlides :: [Block] -> State WriterState [Block]
202toSlides :: [Block] -> State WriterState [Block]
203toSlides bs = do
203toSlides bs = do
204+ opts <- gets stOptions
204− let slideLevel = getSlideLevel bs
205+ let slideLevel = maybe (getSlideLevel bs) id $ writerSlideLevel opts
205 let bs' = prepSlides slideLevel bs
206 let bs' = prepSlides slideLevel bs
206 concat `fmap` (mapM (elementToBeamer slideLevel) $ hierarchicalize bs')
207 concat `fmap` (mapM (elementToBeamer slideLevel) $ hierarchicalize bs')
207
208
@@ -214,7 +215,10 @@ elementToBeamer slideLevel (Sec lvl _num _ident tit elts)
214 : tit ++ [RawInline "latex" "}"] )
215 : tit ++ [RawInline "latex" "}"] )
215 : bs ++ [RawBlock "latex" "\\end{block}"]
216 : bs ++ [RawBlock "latex" "\\end{block}"]
216 | lvl < slideLevel = do
217 | lvl < slideLevel = do
218+ let isSec (Sec _ _ _ _ _) = True
219+ isSec (Blk _) = False
217 bs <- concat `fmap` mapM (elementToBeamer slideLevel) elts
220 bs <- concat `fmap` mapM (elementToBeamer slideLevel) elts
221+ -- (filter isSec elts)
218 return $ (Header lvl tit) : bs
222 return $ (Header lvl tit) : bs
219 | otherwise = do -- lvl == slideLevel
223 | otherwise = do -- lvl == slideLevel
220 -- note: [fragile] is required or verbatim breaks
224 -- note: [fragile] is required or verbatim breaks
src/pandoc.hs+15
@@ -131,6 +131,7 @@ data Opt = Opt
131 , optListings :: Bool -- ^ Use listings package for code blocks
131 , optListings :: Bool -- ^ Use listings package for code blocks
132 , optLaTeXEngine :: String -- ^ Program to use for latex -> pdf
132 , optLaTeXEngine :: String -- ^ Program to use for latex -> pdf
133 , optBeamer :: Bool -- ^ Produce latex output for beamer class
133 , optBeamer :: Bool -- ^ Produce latex output for beamer class
134+ , optSlideLevel :: Maybe Int -- ^ Header level that creates slides
134 }
135 }
135
136
136-- | Defaults for command-line options.
137-- | Defaults for command-line options.
@@ -180,6 +181,7 @@ defaultOpts = Opt
180 , optListings = False
181 , optListings = False
181 , optLaTeXEngine = "pdflatex"
182 , optLaTeXEngine = "pdflatex"
182 , optBeamer = False
183 , optBeamer = False
184+ , optSlideLevel = Nothing
183 }
185 }
184
186
185-- | A list of functions, each transforming the options data structure
187-- | A list of functions, each transforming the options data structure
@@ -381,6 +383,17 @@ options =
381 (\opt -> return opt { optBeamer = True }))
383 (\opt -> return opt { optBeamer = True }))
382 "" -- "Produce latex output for beamer class"
384 "" -- "Produce latex output for beamer class"
383
385
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+
384 , Option "" ["section-divs"]
397 , Option "" ["section-divs"]
385 (NoArg
398 (NoArg
386 (\opt -> return opt { optSectionDivs = True }))
399 (\opt -> return opt { optSectionDivs = True }))
@@ -795,6 +808,7 @@ main = do
795 , optListings = listings
808 , optListings = listings
796 , optLaTeXEngine = latexEngine
809 , optLaTeXEngine = latexEngine
797 , optBeamer = beamer
810 , optBeamer = beamer
811+ , optSlideLevel = slideLevel
798 } = opts
812 } = opts
799
813
800 when dumpArgs $
814 when dumpArgs $
@@ -943,6 +957,7 @@ main = do
943 writerChapters = chapters,
957 writerChapters = chapters,
944 writerListings = listings,
958 writerListings = listings,
945 writerBeamer = beamer,
959 writerBeamer = beamer,
960+ writerSlideLevel = slideLevel,
946 writerHighlight = highlight,
961 writerHighlight = highlight,
947 writerHighlightStyle = highlightStyle }
962 writerHighlightStyle = highlightStyle }
948
963
templates+1−1

Submodule changed.