@@ -79,7 +79,7 @@ pandocToRST (Pandoc meta blocks) = do
7979 (fmap (render colwidth) . blockListToRST)
8080 (fmap (trimr . render colwidth) . inlineListToRST)
8181 $ deleteMeta "title" $ deleteMeta "subtitle" meta
82− body <- blockListToRST blocks
82+ body <- blockListToRST $ normalizeHeadings 1 blocks
8383 notes <- liftM (reverse . stNotes) get >>= notesToRST
8484 -- note that the notes may contain refs, so we do them first
8585 refs <- liftM (reverse . stLinks) get >>= refsToRST
@@ -98,6 +98,13 @@ pandocToRST (Pandoc meta blocks) = do
9898 if writerStandalone opts
9999 then return $ renderTemplate' (writerTemplate opts) context
100100 else return main
101+ where
102+ normalizeHeadings lev (Header l a i:bs) = Header lev a i:normalizeHeadings (lev+1) cont ++ normalizeHeadings lev bs'
103+ where (cont,bs') = break (headerLtEq l) bs
104+ headerLtEq level (Header l' _ _) = l' <= level
105+ headerLtEq _ _ = False
106+ normalizeHeadings lev (b:bs) = b:normalizeHeadings lev bs
107+ normalizeHeadings _ [] = []
101108
102109-- | Return RST representation of reference key table.
103110refsToRST :: Refs -> State WriterState Doc