@@ -253,9 +253,7 @@ blacklistedCharStyles = ["Hyperlink"]
253253resolveDependentRunStyle :: PandocMonad m => RunStyle -> DocxContext m RunStyle
254254resolveDependentRunStyle rPr
255255 | Just s <- rParentStyle rPr
256− , getStyleName s `elem` blacklistedCharStyles =
257− return rPr
258− | Just s <- rParentStyle rPr = do
256+ , getStyleName s `notElem` blacklistedCharStyles = do
259257 opts <- asks docxOptions
260258 if isEnabled Ext_styles opts
261259 then return rPr
@@ -318,12 +316,8 @@ runToInlines (Run rs runElems)
318316 let ils = smushInlines (map runElemToInlines runElems)
319317 transform <- runStyleToTransform rPr
320318 return $ transform ils
321−runToInlines (Footnote bps) = do
322− blksList <- smushBlocks <$> mapM bodyPartToBlocks bps
323− return $ note blksList
324−runToInlines (Endnote bps) = do
325− blksList <- smushBlocks <$> mapM bodyPartToBlocks bps
326− return $ note blksList
319+runToInlines (Footnote bps) = note . smushBlocks <$> mapM bodyPartToBlocks bps
320+runToInlines (Endnote bps) = note . smushBlocks <$> mapM bodyPartToBlocks bps
327321runToInlines (InlineDrawing fp title alt bs ext) = do
328322 (lift . lift) $ P.insertMedia fp Nothing bs
329323 return $ imageWith (extentToAttr ext) (T.pack fp) title $ text alt
@@ -455,9 +449,7 @@ parPartToInlines' (Field info runs) =
455449parPartToInlines' NullParPart = return mempty
456450
457451isAnchorSpan :: Inline -> Bool
458−isAnchorSpan (Span (_, classes, kvs) _) =
459− classes == ["anchor"] &&
460− null kvs
452+isAnchorSpan (Span (_, ["anchor"], []) _) = True
461453isAnchorSpan _ = False
462454
463455dummyAnchors :: [T.Text]
@@ -529,31 +521,30 @@ extraInfo f s = do
529521 else id
530522
531523parStyleToTransform :: PandocMonad m => ParagraphStyle -> DocxContext m (Blocks -> Blocks)
532−parStyleToTransform pPr
533− | (c:cs) <- pStyle pPr
534− , getStyleName c `elem` divsToKeep = do
535− let pPr' = pPr { pStyle = cs }
536− transform <- parStyleToTransform pPr'
537− return $ divWith ("", [normalizeToClassName $ getStyleName c], []) . transform
538− | (c:cs) <- pStyle pPr,
539− getStyleName c `elem` listParagraphStyles = do
540− let pPr' = pPr { pStyle = cs, indentation = Nothing}
541− transform <- parStyleToTransform pPr'
542− return $ divWith ("", [normalizeToClassName $ getStyleName c], []) . transform
543− | (c:cs) <- pStyle pPr = do
544− let pPr' = pPr { pStyle = cs }
545− transform <- parStyleToTransform pPr'
546− ei <- extraInfo divWith c
547− return $ ei . (if isBlockQuote c then blockQuote else id) . transform
548− | null (pStyle pPr)
549− , Just left <- indentation pPr >>= leftParIndent = do
550− let pPr' = pPr { indentation = Nothing }
551− hang = fromMaybe 0 $ indentation pPr >>= hangingParIndent
552− transform <- parStyleToTransform pPr'
553− return $ if (left - hang) > 0
554− then blockQuote . transform
555− else transform
556−parStyleToTransform _ = return id
524+parStyleToTransform pPr = case pStyle pPr of
525+ c@(getStyleName -> styleName):cs
526+ | styleName `elem` divsToKeep -> do
527+ let pPr' = pPr { pStyle = cs }
528+ transform <- parStyleToTransform pPr'
529+ return $ divWith ("", [normalizeToClassName styleName], []) . transform
530+ | styleName `elem` listParagraphStyles -> do
531+ let pPr' = pPr { pStyle = cs, indentation = Nothing}
532+ transform <- parStyleToTransform pPr'
533+ return $ divWith ("", [normalizeToClassName styleName], []) . transform
534+ | otherwise -> do
535+ let pPr' = pPr { pStyle = cs }
536+ transform <- parStyleToTransform pPr'
537+ ei <- extraInfo divWith c
538+ return $ ei . (if isBlockQuote c then blockQuote else id) . transform
539+ []
540+ | Just left <- indentation pPr >>= leftParIndent -> do
541+ let pPr' = pPr { indentation = Nothing }
542+ hang = fromMaybe 0 $ indentation pPr >>= hangingParIndent
543+ transform <- parStyleToTransform pPr'
544+ return $ if (left - hang) > 0
545+ then blockQuote . transform
546+ else transform
547+ | otherwise -> return id
557548
558549normalizeToClassName :: (FromStyleName a) => a -> T.Text
559550normalizeToClassName = T.map go . fromStyleName
@@ -590,47 +581,41 @@ bodyPartToBlocks (Paragraph pPr parparts)
590581 then do modify $ \s -> s { docxDropCap = ils' }
591582 return mempty
592583 else do modify $ \s -> s { docxDropCap = mempty }
593− let ils'' = prevParaIls <>
594− (if isNull prevParaIls then mempty else space) <>
595− ils'
584+ let ils'' = (if isNull prevParaIls then mempty
585+ else prevParaIls <> space) <> ils'
596586 handleInsertion = do
597587 modify $ \s -> s {docxPrevPara = mempty}
598588 transform <- parStyleToTransform pPr'
599589 return $ transform $ paraOrPlain ils''
600590 opts <- asks docxOptions
601− if | isNull ils'' && not (isEnabled Ext_empty_paragraphs opts) ->
591+ case (pChange pPr', readerTrackChanges opts) of
592+ _ | isNull ils'', not (isEnabled Ext_empty_paragraphs opts) ->
602593 return mempty
603− | Just (TrackedChange Insertion _) <- pChange pPr'
604− , AcceptChanges <- readerTrackChanges opts ->
594+ (Just (TrackedChange Insertion _), AcceptChanges) ->
605595 handleInsertion
606− | Just (TrackedChange Insertion _) <- pChange pPr'
607− , RejectChanges <- readerTrackChanges opts -> do
596+ (Just (TrackedChange Insertion _), RejectChanges) -> do
608597 modify $ \s -> s {docxPrevPara = ils''}
609598 return mempty
610− | Just (TrackedChange Insertion cInfo) <- pChange pPr'
611− , AllChanges <- readerTrackChanges opts
612− , ChangeInfo _ cAuthor cDate <- cInfo -> do
599+ (Just (TrackedChange Insertion (ChangeInfo _ cAuthor cDate))
600+ , AllChanges) -> do
613601 let attr = ("", ["paragraph-insertion"], [("author", cAuthor), ("date", cDate)])
614602 insertMark = spanWith attr mempty
615603 transform <- parStyleToTransform pPr'
616604 return $ transform $
617605 paraOrPlain $ ils'' <> insertMark
618− | Just (TrackedChange Deletion _) <- pChange pPr'
619− , AcceptChanges <- readerTrackChanges opts -> do
606+ (Just (TrackedChange Deletion _), AcceptChanges) -> do
620607 modify $ \s -> s {docxPrevPara = ils''}
621608 return mempty
622− | Just (TrackedChange Deletion _) <- pChange pPr'
623− , RejectChanges <- readerTrackChanges opts ->
609+ (Just (TrackedChange Deletion _), RejectChanges) ->
624610 handleInsertion
625− | Just (TrackedChange Deletion cInfo) <- pChange pPr'
626− , AllChanges <- readerTrackChanges opts
627− , ChangeInfo _ cAuthor cDate <- cInfo -> do
611+ (Just (TrackedChange Deletion (ChangeInfo _ cAuthor cDate))
612+ , AllChanges) -> do
628613 let attr = ("", ["paragraph-deletion"], [("author", cAuthor), ("date", cDate)])
629614 insertMark = spanWith attr mempty
630615 transform <- parStyleToTransform pPr'
631616 return $ transform $
632617 paraOrPlain $ ils'' <> insertMark
633− | otherwise -> handleInsertion
618+ _ -> handleInsertion
634619bodyPartToBlocks (ListItem pPr numId lvl (Just levelInfo) parparts) = do
635620 -- We check whether this current numId has previously been used,
636621 -- since Docx expects us to pick up where we left off.
@@ -649,11 +634,8 @@ bodyPartToBlocks (ListItem pPr numId lvl (Just levelInfo) parparts) = do
649634 modify $ \st -> st{ docxListState =
650635 -- expire all the continuation data for lists of level > this one:
651636 -- a new level 1 list item resets continuation for level 2+
652− let expireKeys = [ (numid', lvl')
653− | (numid', lvl') <- M.keys listState
654− , lvl' > lvl
655− ]
656− in foldr M.delete (M.insert (numId, lvl) start listState) expireKeys }
637+ let notExpired (_, lvl') _ = lvl' <= lvl
638+ in M.insert (numId, lvl) start (M.filterWithKey notExpired listState) }
657639 blks <- bodyPartToBlocks (Paragraph pPr parparts)
658640 return $ divWith ("", ["list-item"], kvs) blks
659641bodyPartToBlocks (ListItem pPr _ _ _ parparts) =