@@ -61,6 +61,8 @@ module Text.Pandoc.Shared (
61 -- * Pandoc block and inline list processing
61 -- * Pandoc block and inline list processing
62 normalizeSpaces,
62 normalizeSpaces,
63 compactify,
63 compactify,
64 -- * Writer options
66 -- * Writer options
65 WriterOptions (..),
67 WriterOptions (..),
66 defaultWriterOptions,
68 defaultWriterOptions,
@@ -368,6 +370,26 @@ containsPara ((OrderedList items):rest) = (any containsPara items) ||
368 (containsPara rest)
370 (containsPara rest)
369containsPara (x:rest) = containsPara rest
371containsPara (x:rest) = containsPara rest
373+-- | Data structure for defining hierarchical Pandoc documents
374+data Element = Blk Block
375+ | Sec [Inline] [Element] deriving (Eq, Read, Show)
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
382+-- | Convert list of Pandoc blocks into list of Elements (hierarchical)
383+hierarchicalize :: [Block] -> [Element]
384+hierarchicalize [] = []
385+hierarchicalize (block:rest) =
387+ (Header level title) -> let (thisSection, rest') = break (headerAtLeast
389+ (Sec title (hierarchicalize thisSection)):
390+ (hierarchicalize rest')
391+ x -> (Blk x):(hierarchicalize rest)
371-- | Options for writers
393-- | Options for writers
372data WriterOptions = WriterOptions
394data WriterOptions = WriterOptions
373 { writerStandalone :: Bool -- ^ Include header and footer
395 { writerStandalone :: Bool -- ^ Include header and footer
@@ -377,6 +399,7 @@ data WriterOptions = WriterOptions
377 , writerIncludeAfter :: String -- ^ String to include after the body
399 , writerIncludeAfter :: String -- ^ String to include after the body
378 , writerTableOfContents :: Bool -- ^ Include table of contents
400 , writerTableOfContents :: Bool -- ^ Include table of contents
379 , writerS5 :: Bool -- ^ We're writing S5
401 , writerS5 :: Bool -- ^ We're writing S5
402+ , writerIgnoreNotes :: Bool -- ^ Ignore footnotes (used in making toc)
380 , writerIncremental :: Bool -- ^ Incremental S5 lists
403 , writerIncremental :: Bool -- ^ Incremental S5 lists
381 , writerNumberSections :: Bool -- ^ Number sections in LaTeX
404 , writerNumberSections :: Bool -- ^ Number sections in LaTeX
382 , writerStrictMarkdown :: Bool -- ^ Use strict markdown syntax
405 , writerStrictMarkdown :: Bool -- ^ Use strict markdown syntax
@@ -393,6 +416,7 @@ defaultWriterOptions =
393 writerTabStop = 4,
416 writerTabStop = 4,
394 writerTableOfContents = False,
417 writerTableOfContents = False,
395 writerS5 = False,
418 writerS5 = False,
419+ writerIgnoreNotes = False,
396 writerIncremental = False,
420 writerIncremental = False,
397 writerNumberSections = False,
421 writerNumberSections = False,
398 writerIncludeBefore = "",
422 writerIncludeBefore = "",
@@ -434,3 +458,4 @@ refsMatch (x:restx) (y:resty) = (x == y) && refsMatch restx resty
434refsMatch [] x = null x
458refsMatch [] x = null x
435refsMatch x [] = null x
459refsMatch x [] = null x