|
Packit |
dda32d |
{-
|
|
Packit |
dda32d |
Copyright (C) 2012-2017 John MacFarlane <jgm@berkeley.edu>
|
|
Packit |
dda32d |
|
|
Packit |
dda32d |
This program is free software; you can redistribute it and/or modify
|
|
Packit |
dda32d |
it under the terms of the GNU General Public License as published by
|
|
Packit |
dda32d |
the Free Software Foundation; either version 2 of the License, or
|
|
Packit |
dda32d |
(at your option) any later version.
|
|
Packit |
dda32d |
|
|
Packit |
dda32d |
This program is distributed in the hope that it will be useful,
|
|
Packit |
dda32d |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
dda32d |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
dda32d |
GNU General Public License for more details.
|
|
Packit |
dda32d |
|
|
Packit |
dda32d |
You should have received a copy of the GNU General Public License
|
|
Packit |
dda32d |
along with this program; if not, write to the Free Software
|
|
Packit |
dda32d |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
Packit |
dda32d |
-}
|
|
Packit |
dda32d |
|
|
Packit |
dda32d |
{- |
|
|
Packit |
dda32d |
Module : Text.Pandoc.Slides
|
|
Packit |
dda32d |
Copyright : Copyright (C) 2012-2017 John MacFarlane
|
|
Packit |
dda32d |
License : GNU GPL, version 2 or above
|
|
Packit |
dda32d |
|
|
Packit |
dda32d |
Maintainer : John MacFarlane <jgm@berkeley.edu>
|
|
Packit |
dda32d |
Stability : alpha
|
|
Packit |
dda32d |
Portability : portable
|
|
Packit |
dda32d |
|
|
Packit |
dda32d |
Utility functions for splitting documents into slides for slide
|
|
Packit |
dda32d |
show formats (dzslides, revealjs, s5, slidy, slideous, beamer).
|
|
Packit |
dda32d |
-}
|
|
Packit |
dda32d |
module Text.Pandoc.Slides ( getSlideLevel, prepSlides ) where
|
|
Packit |
dda32d |
import Text.Pandoc.Definition
|
|
Packit |
dda32d |
|
|
Packit |
dda32d |
-- | Find level of header that starts slides (defined as the least header
|
|
Packit |
dda32d |
-- level that occurs before a non-header/non-hrule in the blocks).
|
|
Packit |
dda32d |
getSlideLevel :: [Block] -> Int
|
|
Packit |
dda32d |
getSlideLevel = go 6
|
|
Packit |
dda32d |
where go least (Header n _ _ : x : xs)
|
|
Packit |
dda32d |
| n < least && nonHOrHR x = go n xs
|
|
Packit |
dda32d |
| otherwise = go least (x:xs)
|
|
Packit |
dda32d |
go least (_ : xs) = go least xs
|
|
Packit |
dda32d |
go least [] = least
|
|
Packit |
dda32d |
nonHOrHR Header{} = False
|
|
Packit |
dda32d |
nonHOrHR HorizontalRule = False
|
|
Packit |
dda32d |
nonHOrHR _ = True
|
|
Packit |
dda32d |
|
|
Packit |
dda32d |
-- | Prepare a block list to be passed to hierarchicalize.
|
|
Packit |
dda32d |
prepSlides :: Int -> [Block] -> [Block]
|
|
Packit |
dda32d |
prepSlides slideLevel = ensureStartWithH . splitHrule . extractRefsHeader
|
|
Packit |
dda32d |
where splitHrule (HorizontalRule : Header n attr xs : ys)
|
|
Packit |
dda32d |
| n == slideLevel = Header slideLevel attr xs : splitHrule ys
|
|
Packit |
dda32d |
splitHrule (HorizontalRule : xs) = Header slideLevel nullAttr [Str "\0"] :
|
|
Packit |
dda32d |
splitHrule xs
|
|
Packit |
dda32d |
splitHrule (x : xs) = x : splitHrule xs
|
|
Packit |
dda32d |
splitHrule [] = []
|
|
Packit |
dda32d |
extractRefsHeader bs =
|
|
Packit |
dda32d |
case reverse bs of
|
|
Packit |
dda32d |
(Div ("",["references"],[]) (Header n attrs xs : ys) : zs)
|
|
Packit |
dda32d |
-> reverse zs ++ (Header n attrs xs : [Div ("",["references"],[]) ys])
|
|
Packit |
dda32d |
_ -> bs
|
|
Packit |
dda32d |
ensureStartWithH bs@(Header n _ _:_)
|
|
Packit |
dda32d |
| n <= slideLevel = bs
|
|
Packit |
dda32d |
ensureStartWithH bs = Header slideLevel nullAttr [Str "\0"] : bs
|