RTF writer: use toTableOfContents from T.P.W.Shared.

This commit is contained in:
John MacFarlane 2019-01-04 21:27:49 -08:00
parent c4c3fca500
commit 571fede732

View file

@ -119,9 +119,8 @@ writeRTF options doc = do
inlinesToRTF
meta'
body <- blocksToRTF 0 AlignDefault blocks
let isTOCHeader (Header lev _ _) = lev <= writerTOCDepth options
isTOCHeader _ = False
toc <- tableOfContents $ filter isTOCHeader blocks
toc <- blocksToRTF 0 AlignDefault
[toTableOfContents options $ filter isHeaderBlock blocks]
let context = defField "body" body
$ defField "spacer" spacer
$(if writerTableOfContents options
@ -139,20 +138,6 @@ writeRTF options doc = do
('\n':_) -> body
_ -> body ++ "\n"
-- | Construct table of contents from list of header blocks.
tableOfContents :: PandocMonad m => [Block] -> m String
tableOfContents headers = do
let contents = map elementToListItem $ hierarchicalize headers
blocksToRTF 0 AlignDefault
[Header 1 nullAttr [Str "Contents"], BulletList contents]
elementToListItem :: Element -> [Block]
elementToListItem (Blk _) = []
elementToListItem (Sec _ _ _ sectext subsecs) = Plain sectext :
if null subsecs
then []
else [BulletList (map elementToListItem subsecs)]
-- | Convert unicode characters (> 127) into rich text format representation.
handleUnicode :: String -> String
handleUnicode [] = []