git.iko.soy/typeable/pandoc
on master help sign in
Revert "RST writer: tweaks to header normalization."
fb51077John MacFarlane
src/Text/Pandoc/Writers/RST.hs+4−22
@@ -82,7 +82,7 @@ pandocToRST (Pandoc meta blocks) = do
82 (fmap (trimr . render colwidth) . inlineListToRST)
82 (fmap (trimr . render colwidth) . inlineListToRST)
83 $ deleteMeta "title" $ deleteMeta "subtitle" meta
83 $ deleteMeta "title" $ deleteMeta "subtitle" meta
84 let minLev = findMinHeadingLevel Nothing blocks
84 let minLev = findMinHeadingLevel Nothing blocks
85− body <- blockListToRST' True $ normalizeHeadings minLev 0 blocks
85+ body <- blockListToRST' True $ normalizeHeadings minLev blocks
86 notes <- liftM (reverse . stNotes) get >>= notesToRST
86 notes <- liftM (reverse . stNotes) get >>= notesToRST
87 -- note that the notes may contain refs, so we do them first
87 -- note that the notes may contain refs, so we do them first
88 refs <- liftM (reverse . stLinks) get >>= refsToRST
88 refs <- liftM (reverse . stLinks) get >>= refsToRST
@@ -102,30 +102,12 @@ pandocToRST (Pandoc meta blocks) = do
102 then return $ renderTemplate' (writerTemplate opts) context
102 then return $ renderTemplate' (writerTemplate opts) context
103 else return main
103 else return main
104 where
104 where
105− -- Partial normalization:
106− -- We use the underline scheme appropriate for the lowest
107− -- header level found, and we don't normalize headers
108− -- until we've hit the first header with minimum header
109− -- level in the fragment.
110− -- This is intended to help with the problems noted in
111− -- #2079, while still being flexible enough for use
112− -- with fragments that might not include the base
113− -- header level, and might start halfway through a section
114− -- (see #2394).
115− normalizeHeadings minLev lev (Header l a i:bs) =
105+ normalizeHeadings lev (Header l a i:bs) = Header lev a i:normalizeHeadings (lev+1) cont ++ normalizeHeadings lev bs'
116− let lev' = if lev == 0 && l == minLev
117− then minLev
118− else lev
119− in if lev' == 0 -- we haven't hit minLev yet
120− then Header l a i : normalizeHeadings minLev 0 cont ++
121− normalizeHeadings minLev 0 bs'
122− else Header lev' a i : normalizeHeadings minLev (lev' + 1) cont ++
123− normalizeHeadings minLev lev' bs'
124 where (cont,bs') = break (headerLtEq l) bs
106 where (cont,bs') = break (headerLtEq l) bs
125 headerLtEq level (Header l' _ _) = l' <= level
107 headerLtEq level (Header l' _ _) = l' <= level
126 headerLtEq _ _ = False
108 headerLtEq _ _ = False
127− normalizeHeadings minLev lev (b:bs) = b : normalizeHeadings minLev lev bs
109+ normalizeHeadings lev (b:bs) = b:normalizeHeadings lev bs
128− normalizeHeadings _ _ [] = []
110+ normalizeHeadings _ [] = []
129 findMinHeadingLevel Nothing (Header l _a _i:bs) = findMinHeadingLevel (Just l) bs
111 findMinHeadingLevel Nothing (Header l _a _i:bs) = findMinHeadingLevel (Just l) bs
130 findMinHeadingLevel (Just ol) (Header l _a _i:bs) =
112 findMinHeadingLevel (Just ol) (Header l _a _i:bs) =
131 findMinHeadingLevel (Just $ if ol>l then l else ol) bs
113 findMinHeadingLevel (Just $ if ol>l then l else ol) bs