diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs index 321980da351b..10be495ec476 100644 --- a/src/Text/Pandoc/Writers/Docx.hs +++ b/src/Text/Pandoc/Writers/Docx.hs @@ -27,7 +27,7 @@ import Data.Char (isSpace, isLetter) import Data.List (intercalate, isPrefixOf, isSuffixOf) import Data.String (fromString) import qualified Data.Map as M -import Data.Maybe (fromMaybe, isNothing, mapMaybe, maybeToList) +import Data.Maybe (fromMaybe, isNothing, mapMaybe, maybeToList, isJust) import qualified Data.Set as Set import qualified Data.Text as T import Data.Text (Text) @@ -942,7 +942,10 @@ blockToOpenXML' opts el addOpenXMLList marker lst = do addList marker numid <- getNumId - l <- asList $ concat `fmap` mapM (listItemToOpenXML opts numid) lst + exampleid <- case marker of + NumberMarker Example _ _ -> gets stExampleId + _ -> return Nothing + l <- asList $ concat `fmap` mapM (listItemToOpenXML opts $ fromMaybe numid exampleid) lst setFirstPara return l blockToOpenXML' opts (DefinitionList items) = do @@ -963,7 +966,16 @@ definitionListItemToOpenXML opts (term,defs) = do addList :: (PandocMonad m) => ListMarker -> WS m () addList marker = do lists <- gets stLists - modify $ \st -> st{ stLists = lists ++ [marker] } + lastExampleId <- gets stExampleId + modify $ \st -> st{ stLists = lists ++ case marker of + -- Use only first occurence of Example for list declaration to avoid overhead + NumberMarker Example _ _ | isJust lastExampleId -> [] + _ -> [marker] + , stExampleId = case marker of + -- Reuse the same identifier for all other occurences of Example + NumberMarker Example _ _ -> lastExampleId <|> Just (baseListId + length lists) + _ -> lastExampleId + } listItemToOpenXML :: (PandocMonad m) => WriterOptions diff --git a/src/Text/Pandoc/Writers/Docx/Types.hs b/src/Text/Pandoc/Writers/Docx/Types.hs index 15e16cb933d6..967976ac8b5b 100644 --- a/src/Text/Pandoc/Writers/Docx/Types.hs +++ b/src/Text/Pandoc/Writers/Docx/Types.hs @@ -107,6 +107,7 @@ data WriterState = WriterState{ , stExternalLinks :: M.Map Text Text , stImages :: M.Map FilePath (String, String, Maybe MimeType, B.ByteString) , stLists :: [ListMarker] + , stExampleId :: Maybe Int , stInsId :: Int , stDelId :: Int , stStyleMaps :: StyleMaps @@ -131,6 +132,7 @@ defaultWriterState = WriterState{ , stExternalLinks = M.empty , stImages = M.empty , stLists = [NoMarker] + , stExampleId = Nothing , stInsId = 1 , stDelId = 1 , stStyleMaps = StyleMaps M.empty M.empty