@@ -2,6 +2,7 @@
2{-# LANGUAGE CPP #-}
2{-# LANGUAGE CPP #-}
3{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE PatternGuards #-}
4{-# LANGUAGE PatternGuards #-}
5+{-# LANGUAGE MultiWayIf #-}
6 Module : Text.Pandoc.Readers.Docx
7 Module : Text.Pandoc.Readers.Docx
7 Copyright : Copyright (C) 2014-2019 Jesse Rosenthal
8 Copyright : Copyright (C) 2014-2019 Jesse Rosenthal
@@ -129,7 +130,7 @@ instance Default DEnv where
129type DocxContext m = ReaderT DEnv (StateT DState m)
130type DocxContext m = ReaderT DEnv (StateT DState m)
131evalDocxContext :: PandocMonad m => DocxContext m a -> DEnv -> DState -> m a
132evalDocxContext :: PandocMonad m => DocxContext m a -> DEnv -> DState -> m a
132−evalDocxContext ctx env st = flip evalStateT st $flip runReaderT env ctx
133+evalDocxContext ctx env st = flip evalStateT st $ runReaderT ctx env
134-- This is empty, but we put it in for future-proofing.
135-- This is empty, but we put it in for future-proofing.
135spansToKeep :: [String]
136spansToKeep :: [String]
@@ -537,15 +538,6 @@ parStyleToTransform pPr
537 let pPr' = pPr { pStyle = cs, indentation = Nothing}
538 let pPr' = pPr { pStyle = cs, indentation = Nothing}
538 transform <- parStyleToTransform pPr'
539 transform <- parStyleToTransform pPr'
539 return $ divWith ("", [c], []) . transform
540 return $ divWith ("", [c], []) . transform
540− | (c:cs) <- pStyle pPr
541− , Just True <- pBlockQuote pPr = do
542− opts <- asks docxOptions
543− let pPr' = pPr { pStyle = cs }
544− transform <- parStyleToTransform pPr'
545− let extraInfo = if isEnabled Ext_styles opts
546− then divWith ("", [], [("custom-style", c)])
548− return $ extraInfo . blockQuote . transform
549 | (c:cs) <- pStyle pPr = do
541 | (c:cs) <- pStyle pPr = do
550 opts <- asks docxOptions
542 opts <- asks docxOptions
551 let pPr' = pPr { pStyle = cs}
543 let pPr' = pPr { pStyle = cs}
@@ -553,22 +545,15 @@ parStyleToTransform pPr
553 let extraInfo = if isEnabled Ext_styles opts
545 let extraInfo = if isEnabled Ext_styles opts
554 then divWith ("", [], [("custom-style", c)])
546 then divWith ("", [], [("custom-style", c)])
556− return $ extraInfo . transform
548+ return $ extraInfo . (if fromMaybe False (pBlockQuote pPr) then blockQuote else id) . transform
557 | null (pStyle pPr)
549 | null (pStyle pPr)
558− , Just left <- indentation pPr >>= leftParIndent
550+ , Just left <- indentation pPr >>= leftParIndent = do
559− , Just hang <- indentation pPr >>= hangingParIndent = do
560 let pPr' = pPr { indentation = Nothing }
551 let pPr' = pPr { indentation = Nothing }
552+ hang = fromMaybe 0 $ indentation pPr >>= hangingParIndent
561 transform <- parStyleToTransform pPr'
553 transform <- parStyleToTransform pPr'
562− return $ case (left - hang) > 0 of
554+ return $ if (left - hang) > 0
563− True -> blockQuote . transform
565− | null (pStyle pPr),
566− Just left <- indentation pPr >>= leftParIndent = do
567− let pPr' = pPr { indentation = Nothing }
568− transform <- parStyleToTransform pPr'
569− return $ case left > 0 of
570− True -> blockQuote . transform
555+ then blockQuote . transform
571− False -> transform
556+ else transform
572parStyleToTransform _ = return id
557parStyleToTransform _ = return id
574bodyPartToBlocks :: PandocMonad m => BodyPart -> DocxContext m Blocks
559bodyPartToBlocks :: PandocMonad m => BodyPart -> DocxContext m Blocks
@@ -585,7 +570,7 @@ bodyPartToBlocks (Paragraph pPr parparts)
585 makeHeaderAnchor $
570 makeHeaderAnchor $
586 headerWith ("", delete style (pStyle pPr), []) n ils
571 headerWith ("", delete style (pStyle pPr), []) n ils
587 | otherwise = do
572 | otherwise = do
588− ils <- (trimSps . smushInlines) <$> mapM parPartToInlines parparts
573+ ils <- trimSps . smushInlines <$> mapM parPartToInlines parparts
589 prevParaIls <- gets docxPrevPara
574 prevParaIls <- gets docxPrevPara
590 dropIls <- gets docxDropCap
575 dropIls <- gets docxDropCap
591 let ils' = dropIls <> ils
576 let ils' = dropIls <> ils
@@ -596,21 +581,21 @@ bodyPartToBlocks (Paragraph pPr parparts)
596 let ils'' = prevParaIls <>
581 let ils'' = prevParaIls <>
597 (if isNull prevParaIls then mempty else space) <>
582 (if isNull prevParaIls then mempty else space) <>
584+ handleInsertion = do
585+ modify $ \s -> s {docxPrevPara = mempty}
586+ transform <- parStyleToTransform pPr
587+ return $ transform $ para ils''
599 opts <- asks docxOptions
588 opts <- asks docxOptions
602− _ | isNull ils'' && not (isEnabled Ext_empty_paragraphs opts) ->
589+ if | isNull ils'' && not (isEnabled Ext_empty_paragraphs opts) ->
603 return mempty
590 return mempty
604− _ | Just (TrackedChange Insertion _) <- pChange pPr
591+ | Just (TrackedChange Insertion _) <- pChange pPr
605− , AcceptChanges <- readerTrackChanges opts -> do
592+ , AcceptChanges <- readerTrackChanges opts ->
606− modify $ \s -> s {docxPrevPara = mempty}
593+ handleInsertion
607− transform <- parStyleToTransform pPr
608− return $ transform $ para ils''
609− _ | Just (TrackedChange Insertion _) <- pChange pPr
594+ | Just (TrackedChange Insertion _) <- pChange pPr
610 , RejectChanges <- readerTrackChanges opts -> do
595 , RejectChanges <- readerTrackChanges opts -> do
611 modify $ \s -> s {docxPrevPara = ils''}
596 modify $ \s -> s {docxPrevPara = ils''}
612 return mempty
597 return mempty
613− _ | Just (TrackedChange Insertion cInfo) <- pChange pPr
598+ | Just (TrackedChange Insertion cInfo) <- pChange pPr
614 , AllChanges <- readerTrackChanges opts
599 , AllChanges <- readerTrackChanges opts
615 , ChangeInfo _ cAuthor cDate <- cInfo -> do
600 , ChangeInfo _ cAuthor cDate <- cInfo -> do
616 let attr = ("", ["paragraph-insertion"], [("author", cAuthor), ("date", cDate)])
601 let attr = ("", ["paragraph-insertion"], [("author", cAuthor), ("date", cDate)])
@@ -618,16 +603,14 @@ bodyPartToBlocks (Paragraph pPr parparts)
618 transform <- parStyleToTransform pPr
603 transform <- parStyleToTransform pPr
619 return $ transform $
604 return $ transform $
620 para $ ils'' <> insertMark
605 para $ ils'' <> insertMark
621− _ | Just (TrackedChange Deletion _) <- pChange pPr
606+ | Just (TrackedChange Deletion _) <- pChange pPr
622 , AcceptChanges <- readerTrackChanges opts -> do
607 , AcceptChanges <- readerTrackChanges opts -> do
623 modify $ \s -> s {docxPrevPara = ils''}
608 modify $ \s -> s {docxPrevPara = ils''}
624 return mempty
609 return mempty
625− _ | Just (TrackedChange Deletion _) <- pChange pPr
610+ | Just (TrackedChange Deletion _) <- pChange pPr
626− , RejectChanges <- readerTrackChanges opts -> do
611+ , RejectChanges <- readerTrackChanges opts ->
627− modify $ \s -> s {docxPrevPara = mempty}
612+ handleInsertion
628− transform <- parStyleToTransform pPr
629− return $ transform $ para ils''
630− _ | Just (TrackedChange Deletion cInfo) <- pChange pPr
613+ | Just (TrackedChange Deletion cInfo) <- pChange pPr
631 , AllChanges <- readerTrackChanges opts
614 , AllChanges <- readerTrackChanges opts
632 , ChangeInfo _ cAuthor cDate <- cInfo -> do
615 , ChangeInfo _ cAuthor cDate <- cInfo -> do
633 let attr = ("", ["paragraph-deletion"], [("author", cAuthor), ("date", cDate)])
616 let attr = ("", ["paragraph-deletion"], [("author", cAuthor), ("date", cDate)])
@@ -635,10 +618,7 @@ bodyPartToBlocks (Paragraph pPr parparts)
635 transform <- parStyleToTransform pPr
618 transform <- parStyleToTransform pPr
636 return $ transform $
619 return $ transform $
637 para $ ils'' <> insertMark
620 para $ ils'' <> insertMark
638− _ | otherwise -> do
621+ | otherwise -> handleInsertion
639− modify $ \s -> s {docxPrevPara = mempty}
640− transform <- parStyleToTransform pPr
641− return $ transform $ para ils''
642bodyPartToBlocks (ListItem pPr numId lvl (Just levelInfo) parparts) = do
622bodyPartToBlocks (ListItem pPr numId lvl (Just levelInfo) parparts) = do
643 -- We check whether this current numId has previously been used,
623 -- We check whether this current numId has previously been used,
644 -- since Docx expects us to pick up where we left off.
624 -- since Docx expects us to pick up where we left off.