@@ -253,9 +253,7 @@ blacklistedCharStyles = ["Hyperlink"]
253resolveDependentRunStyle :: PandocMonad m => RunStyle -> DocxContext m RunStyle
253resolveDependentRunStyle :: PandocMonad m => RunStyle -> DocxContext m RunStyle
254resolveDependentRunStyle rPr
254resolveDependentRunStyle rPr
255 | Just s <- rParentStyle rPr
255 | Just s <- rParentStyle rPr
256− , getStyleName s `elem` blacklistedCharStyles =
256+ , getStyleName s `notElem` blacklistedCharStyles = do
258− | Just s <- rParentStyle rPr = do
259 opts <- asks docxOptions
257 opts <- asks docxOptions
260 if isEnabled Ext_styles opts
258 if isEnabled Ext_styles opts
261 then return rPr
259 then return rPr
@@ -318,12 +316,8 @@ runToInlines (Run rs runElems)
318 let ils = smushInlines (map runElemToInlines runElems)
316 let ils = smushInlines (map runElemToInlines runElems)
319 transform <- runStyleToTransform rPr
317 transform <- runStyleToTransform rPr
320 return $ transform ils
318 return $ transform ils
321−runToInlines (Footnote bps) = do
322− blksList <- smushBlocks <$> mapM bodyPartToBlocks bps
319+runToInlines (Footnote bps) = note . smushBlocks <$> mapM bodyPartToBlocks bps
323− return $ note blksList
324−runToInlines (Endnote bps) = do
325− blksList <- smushBlocks <$> mapM bodyPartToBlocks bps
320+runToInlines (Endnote bps) = note . smushBlocks <$> mapM bodyPartToBlocks bps
326− return $ note blksList
327runToInlines (InlineDrawing fp title alt bs ext) = do
321runToInlines (InlineDrawing fp title alt bs ext) = do
328 (lift . lift) $ P.insertMedia fp Nothing bs
322 (lift . lift) $ P.insertMedia fp Nothing bs
329 return $ imageWith (extentToAttr ext) (T.pack fp) title $ text alt
323 return $ imageWith (extentToAttr ext) (T.pack fp) title $ text alt
@@ -455,9 +449,7 @@ parPartToInlines' (Field info runs) =
455parPartToInlines' NullParPart = return mempty
449parPartToInlines' NullParPart = return mempty
457isAnchorSpan :: Inline -> Bool
451isAnchorSpan :: Inline -> Bool
458−isAnchorSpan (Span (_, classes, kvs) _) =
452+isAnchorSpan (Span (_, ["anchor"], []) _) = True
459− classes == ["anchor"] &&
461isAnchorSpan _ = False
453isAnchorSpan _ = False
463dummyAnchors :: [T.Text]
455dummyAnchors :: [T.Text]
@@ -529,31 +521,30 @@ extraInfo f s = do
531parStyleToTransform :: PandocMonad m => ParagraphStyle -> DocxContext m (Blocks -> Blocks)
523parStyleToTransform :: PandocMonad m => ParagraphStyle -> DocxContext m (Blocks -> Blocks)
532−parStyleToTransform pPr
524+parStyleToTransform pPr = case pStyle pPr of
533− | (c:cs) <- pStyle pPr
525+ c@(getStyleName -> styleName):cs
534− , getStyleName c `elem` divsToKeep = do
526+ | styleName `elem` divsToKeep -> do
535− let pPr' = pPr { pStyle = cs }
527+ let pPr' = pPr { pStyle = cs }
536− transform <- parStyleToTransform pPr'
528+ transform <- parStyleToTransform pPr'
537− return $ divWith ("", [normalizeToClassName $ getStyleName c], []) . transform
529+ return $ divWith ("", [normalizeToClassName styleName], []) . transform
538− | (c:cs) <- pStyle pPr,
539− getStyleName c `elem` listParagraphStyles = do
530+ | styleName `elem` listParagraphStyles -> do
540− let pPr' = pPr { pStyle = cs, indentation = Nothing}
531+ let pPr' = pPr { pStyle = cs, indentation = Nothing}
541− transform <- parStyleToTransform pPr'
532+ transform <- parStyleToTransform pPr'
542− return $ divWith ("", [normalizeToClassName $ getStyleName c], []) . transform
533+ return $ divWith ("", [normalizeToClassName styleName], []) . transform
543− | (c:cs) <- pStyle pPr = do
534+ | otherwise -> do
544− let pPr' = pPr { pStyle = cs }
535+ let pPr' = pPr { pStyle = cs }
545− transform <- parStyleToTransform pPr'
536+ transform <- parStyleToTransform pPr'
546− ei <- extraInfo divWith c
537+ ei <- extraInfo divWith c
547− return $ ei . (if isBlockQuote c then blockQuote else id) . transform
538+ return $ ei . (if isBlockQuote c then blockQuote else id) . transform
548− | null (pStyle pPr)
539+ []
549− , Just left <- indentation pPr >>= leftParIndent = do
540+ | Just left <- indentation pPr >>= leftParIndent -> do
550− let pPr' = pPr { indentation = Nothing }
541+ let pPr' = pPr { indentation = Nothing }
551− hang = fromMaybe 0 $ indentation pPr >>= hangingParIndent
542+ hang = fromMaybe 0 $ indentation pPr >>= hangingParIndent
552− transform <- parStyleToTransform pPr'
543+ transform <- parStyleToTransform pPr'
553− return $ if (left - hang) > 0
544+ return $ if (left - hang) > 0
554− then blockQuote . transform
545+ then blockQuote . transform
555− else transform
546+ else transform
556−parStyleToTransform _ = return id
547+ | otherwise -> return id
558normalizeToClassName :: (FromStyleName a) => a -> T.Text
549normalizeToClassName :: (FromStyleName a) => a -> T.Text
559normalizeToClassName = T.map go . fromStyleName
550normalizeToClassName = T.map go . fromStyleName
@@ -590,47 +581,41 @@ bodyPartToBlocks (Paragraph pPr parparts)
590 then do modify $ \s -> s { docxDropCap = ils' }
581 then do modify $ \s -> s { docxDropCap = ils' }
591 return mempty
582 return mempty
592 else do modify $ \s -> s { docxDropCap = mempty }
583 else do modify $ \s -> s { docxDropCap = mempty }
593− let ils'' = prevParaIls <>
594− (if isNull prevParaIls then mempty else space) <>
584+ let ils'' = (if isNull prevParaIls then mempty
595− ils'
585+ else prevParaIls <> space) <> ils'
596 handleInsertion = do
586 handleInsertion = do
597 modify $ \s -> s {docxPrevPara = mempty}
587 modify $ \s -> s {docxPrevPara = mempty}
598 transform <- parStyleToTransform pPr'
588 transform <- parStyleToTransform pPr'
599 return $ transform $ paraOrPlain ils''
589 return $ transform $ paraOrPlain ils''
600 opts <- asks docxOptions
590 opts <- asks docxOptions
591+ case (pChange pPr', readerTrackChanges opts) of
601− if | isNull ils'' && not (isEnabled Ext_empty_paragraphs opts) ->
592+ _ | isNull ils'', not (isEnabled Ext_empty_paragraphs opts) ->
602 return mempty
593 return mempty
603− | Just (TrackedChange Insertion _) <- pChange pPr'
594+ (Just (TrackedChange Insertion _), AcceptChanges) ->
604− , AcceptChanges <- readerTrackChanges opts ->
605 handleInsertion
595 handleInsertion
606− | Just (TrackedChange Insertion _) <- pChange pPr'
596+ (Just (TrackedChange Insertion _), RejectChanges) -> do
607− , RejectChanges <- readerTrackChanges opts -> do
608 modify $ \s -> s {docxPrevPara = ils''}
597 modify $ \s -> s {docxPrevPara = ils''}
609 return mempty
598 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))
613 let attr = ("", ["paragraph-insertion"], [("author", cAuthor), ("date", cDate)])
601 let attr = ("", ["paragraph-insertion"], [("author", cAuthor), ("date", cDate)])
614 insertMark = spanWith attr mempty
602 insertMark = spanWith attr mempty
615 transform <- parStyleToTransform pPr'
603 transform <- parStyleToTransform pPr'
616 return $ transform $
604 return $ transform $
617 paraOrPlain $ ils'' <> insertMark
605 paraOrPlain $ ils'' <> insertMark
618− | Just (TrackedChange Deletion _) <- pChange pPr'
606+ (Just (TrackedChange Deletion _), AcceptChanges) -> do
619− , AcceptChanges <- readerTrackChanges opts -> do
620 modify $ \s -> s {docxPrevPara = ils''}
607 modify $ \s -> s {docxPrevPara = ils''}
621 return mempty
608 return mempty
622− | Just (TrackedChange Deletion _) <- pChange pPr'
609+ (Just (TrackedChange Deletion _), RejectChanges) ->
623− , RejectChanges <- readerTrackChanges opts ->
624 handleInsertion
610 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))
628 let attr = ("", ["paragraph-deletion"], [("author", cAuthor), ("date", cDate)])
613 let attr = ("", ["paragraph-deletion"], [("author", cAuthor), ("date", cDate)])
629 insertMark = spanWith attr mempty
614 insertMark = spanWith attr mempty
630 transform <- parStyleToTransform pPr'
615 transform <- parStyleToTransform pPr'
631 return $ transform $
616 return $ transform $
632 paraOrPlain $ ils'' <> insertMark
617 paraOrPlain $ ils'' <> insertMark
633− | otherwise -> handleInsertion
618+ _ -> handleInsertion
634bodyPartToBlocks (ListItem pPr numId lvl (Just levelInfo) parparts) = do
619bodyPartToBlocks (ListItem pPr numId lvl (Just levelInfo) parparts) = do
635 -- We check whether this current numId has previously been used,
620 -- We check whether this current numId has previously been used,
636 -- since Docx expects us to pick up where we left off.
621 -- since Docx expects us to pick up where we left off.
@@ -649,11 +634,8 @@ bodyPartToBlocks (ListItem pPr numId lvl (Just levelInfo) parparts) = do
649 modify $ \st -> st{ docxListState =
634 modify $ \st -> st{ docxListState =
650 -- expire all the continuation data for lists of level > this one:
635 -- expire all the continuation data for lists of level > this one:
651 -- a new level 1 list item resets continuation for level 2+
636 -- a new level 1 list item resets continuation for level 2+
652− let expireKeys = [ (numid', lvl')
637+ let notExpired (_, lvl') _ = lvl' <= lvl
653− | (numid', lvl') <- M.keys listState
656− in foldr M.delete (M.insert (numId, lvl) start listState) expireKeys }
638+ in M.insert (numId, lvl) start (M.filterWithKey notExpired listState) }
657 blks <- bodyPartToBlocks (Paragraph pPr parparts)
639 blks <- bodyPartToBlocks (Paragraph pPr parparts)
658 return $ divWith ("", ["list-item"], kvs) blks
640 return $ divWith ("", ["list-item"], kvs) blks
659bodyPartToBlocks (ListItem pPr _ _ _ parparts) =
641bodyPartToBlocks (ListItem pPr _ _ _ parparts) =