@@ -61,6 +61,8 @@ module Text.Pandoc.Shared (
6161 -- * Pandoc block and inline list processing
6262 normalizeSpaces,
6363 compactify,
64+ Element (..),
65+ hierarchicalize,
6466 -- * Writer options
6567 WriterOptions (..),
6668 defaultWriterOptions,
@@ -368,6 +370,26 @@ containsPara ((OrderedList items):rest) = (any containsPara items) ||
368370 (containsPara rest)
369371containsPara (x:rest) = containsPara rest
370372
373+-- | Data structure for defining hierarchical Pandoc documents
374+data Element = Blk Block
375+ | Sec [Inline] [Element] deriving (Eq, Read, Show)
376+
377+-- | Returns true on Header block with level at least 'level'
378+headerAtLeast :: Int -> Block -> Bool
379+headerAtLeast level (Header x _) = x <= level
380+headerAtLeast level _ = False
381+
382+-- | Convert list of Pandoc blocks into list of Elements (hierarchical)
383+hierarchicalize :: [Block] -> [Element]
384+hierarchicalize [] = []
385+hierarchicalize (block:rest) =
386+ case block of
387+ (Header level title) -> let (thisSection, rest') = break (headerAtLeast
388+ level) rest in
389+ (Sec title (hierarchicalize thisSection)):
390+ (hierarchicalize rest')
391+ x -> (Blk x):(hierarchicalize rest)
392+
371393-- | Options for writers
372394data WriterOptions = WriterOptions
373395 { writerStandalone :: Bool -- ^ Include header and footer
@@ -377,6 +399,7 @@ data WriterOptions = WriterOptions
377399 , writerIncludeAfter :: String -- ^ String to include after the body
378400 , writerTableOfContents :: Bool -- ^ Include table of contents
379401 , writerS5 :: Bool -- ^ We're writing S5
402+ , writerIgnoreNotes :: Bool -- ^ Ignore footnotes (used in making toc)
380403 , writerIncremental :: Bool -- ^ Incremental S5 lists
381404 , writerNumberSections :: Bool -- ^ Number sections in LaTeX
382405 , writerStrictMarkdown :: Bool -- ^ Use strict markdown syntax
@@ -393,6 +416,7 @@ defaultWriterOptions =
393416 writerTabStop = 4,
394417 writerTableOfContents = False,
395418 writerS5 = False,
419+ writerIgnoreNotes = False,
396420 writerIncremental = False,
397421 writerNumberSections = False,
398422 writerIncludeBefore = "",
@@ -434,3 +458,4 @@ refsMatch (x:restx) (y:resty) = (x == y) && refsMatch restx resty
434458refsMatch [] x = null x
435459refsMatch x [] = null x
436460
461+