@@ -2,6 +2,7 @@
22{-# LANGUAGE CPP #-}
33{-# LANGUAGE OverloadedStrings #-}
44{-# LANGUAGE PatternGuards #-}
5+{-# LANGUAGE MultiWayIf #-}
56{- |
67 Module : Text.Pandoc.Readers.Docx
78 Copyright : Copyright (C) 2014-2019 Jesse Rosenthal
@@ -129,7 +130,7 @@ instance Default DEnv where
129130type DocxContext m = ReaderT DEnv (StateT DState m)
130131
131132evalDocxContext :: 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
133134
134135-- This is empty, but we put it in for future-proofing.
135136spansToKeep :: [String]
@@ -537,15 +538,6 @@ parStyleToTransform pPr
537538 let pPr' = pPr { pStyle = cs, indentation = Nothing}
538539 transform <- parStyleToTransform pPr'
539540 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)])
547− else id
548− return $ extraInfo . blockQuote . transform
549541 | (c:cs) <- pStyle pPr = do
550542 opts <- asks docxOptions
551543 let pPr' = pPr { pStyle = cs}
@@ -553,22 +545,15 @@ parStyleToTransform pPr
553545 let extraInfo = if isEnabled Ext_styles opts
554546 then divWith ("", [], [("custom-style", c)])
555547 else id
556− return $ extraInfo . transform
548+ return $ extraInfo . (if fromMaybe False (pBlockQuote pPr) then blockQuote else id) . transform
557549 | null (pStyle pPr)
558− , Just left <- indentation pPr >>= leftParIndent
559− , Just hang <- indentation pPr >>= hangingParIndent = do
550+ , Just left <- indentation pPr >>= leftParIndent = do
560551 let pPr' = pPr { indentation = Nothing }
552+ hang = fromMaybe 0 $ indentation pPr >>= hangingParIndent
561553 transform <- parStyleToTransform pPr'
562− return $ case (left - hang) > 0 of
563− True -> blockQuote . transform
564− False -> 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
571− False -> transform
554+ return $ if (left - hang) > 0
555+ then blockQuote . transform
556+ else transform
572557parStyleToTransform _ = return id
573558
574559bodyPartToBlocks :: PandocMonad m => BodyPart -> DocxContext m Blocks
@@ -585,7 +570,7 @@ bodyPartToBlocks (Paragraph pPr parparts)
585570 makeHeaderAnchor $
586571 headerWith ("", delete style (pStyle pPr), []) n ils
587572 | otherwise = do
588− ils <- (trimSps . smushInlines) <$> mapM parPartToInlines parparts
573+ ils <- trimSps . smushInlines <$> mapM parPartToInlines parparts
589574 prevParaIls <- gets docxPrevPara
590575 dropIls <- gets docxDropCap
591576 let ils' = dropIls <> ils
@@ -596,21 +581,21 @@ bodyPartToBlocks (Paragraph pPr parparts)
596581 let ils'' = prevParaIls <>
597582 (if isNull prevParaIls then mempty else space) <>
598583 ils'
584+ handleInsertion = do
585+ modify $ \s -> s {docxPrevPara = mempty}
586+ transform <- parStyleToTransform pPr
587+ return $ transform $ para ils''
599588 opts <- asks docxOptions
600− case () of
601−
602− _ | isNull ils'' && not (isEnabled Ext_empty_paragraphs opts) ->
589+ if | isNull ils'' && not (isEnabled Ext_empty_paragraphs opts) ->
603590 return mempty
604− _ | Just (TrackedChange Insertion _) <- pChange pPr
605− , AcceptChanges <- readerTrackChanges opts -> do
606− modify $ \s -> s {docxPrevPara = mempty}
607− transform <- parStyleToTransform pPr
608− return $ transform $ para ils''
609− _ | Just (TrackedChange Insertion _) <- pChange pPr
591+ | Just (TrackedChange Insertion _) <- pChange pPr
592+ , AcceptChanges <- readerTrackChanges opts ->
593+ handleInsertion
594+ | Just (TrackedChange Insertion _) <- pChange pPr
610595 , RejectChanges <- readerTrackChanges opts -> do
611596 modify $ \s -> s {docxPrevPara = ils''}
612597 return mempty
613− _ | Just (TrackedChange Insertion cInfo) <- pChange pPr
598+ | Just (TrackedChange Insertion cInfo) <- pChange pPr
614599 , AllChanges <- readerTrackChanges opts
615600 , ChangeInfo _ cAuthor cDate <- cInfo -> do
616601 let attr = ("", ["paragraph-insertion"], [("author", cAuthor), ("date", cDate)])
@@ -618,16 +603,14 @@ bodyPartToBlocks (Paragraph pPr parparts)
618603 transform <- parStyleToTransform pPr
619604 return $ transform $
620605 para $ ils'' <> insertMark
621− _ | Just (TrackedChange Deletion _) <- pChange pPr
606+ | Just (TrackedChange Deletion _) <- pChange pPr
622607 , AcceptChanges <- readerTrackChanges opts -> do
623608 modify $ \s -> s {docxPrevPara = ils''}
624609 return mempty
625− _ | Just (TrackedChange Deletion _) <- pChange pPr
626− , RejectChanges <- readerTrackChanges opts -> do
627− modify $ \s -> s {docxPrevPara = mempty}
628− transform <- parStyleToTransform pPr
629− return $ transform $ para ils''
630− _ | Just (TrackedChange Deletion cInfo) <- pChange pPr
610+ | Just (TrackedChange Deletion _) <- pChange pPr
611+ , RejectChanges <- readerTrackChanges opts ->
612+ handleInsertion
613+ | Just (TrackedChange Deletion cInfo) <- pChange pPr
631614 , AllChanges <- readerTrackChanges opts
632615 , ChangeInfo _ cAuthor cDate <- cInfo -> do
633616 let attr = ("", ["paragraph-deletion"], [("author", cAuthor), ("date", cDate)])
@@ -635,10 +618,7 @@ bodyPartToBlocks (Paragraph pPr parparts)
635618 transform <- parStyleToTransform pPr
636619 return $ transform $
637620 para $ ils'' <> insertMark
638− _ | otherwise -> do
639− modify $ \s -> s {docxPrevPara = mempty}
640− transform <- parStyleToTransform pPr
641− return $ transform $ para ils''
621+ | otherwise -> handleInsertion
642622bodyPartToBlocks (ListItem pPr numId lvl (Just levelInfo) parparts) = do
643623 -- We check whether this current numId has previously been used,
644624 -- since Docx expects us to pick up where we left off.