aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text/Pandoc/Readers/Docx.hs37
-rw-r--r--test/Tests/Readers/Docx.hs8
-rw-r--r--test/docx/lists_continuing.docxbin0 -> 17717 bytes
-rw-r--r--test/docx/lists_continuing.native7
-rw-r--r--test/docx/lists_restarting.docxbin0 -> 18189 bytes
-rw-r--r--test/docx/lists_restarting.native8
6 files changed, 45 insertions, 15 deletions
diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs
index 651d46753..7c7845c71 100644
--- a/src/Text/Pandoc/Readers/Docx.hs
+++ b/src/Text/Pandoc/Readers/Docx.hs
@@ -121,6 +121,9 @@ data DState = DState { docxAnchorMap :: M.Map String String
, docxMediaBag :: MediaBag
, docxDropCap :: Inlines
, docxWarnings :: [String]
+ -- keep track of (numId, lvl) values for
+ -- restarting
+ , docxListState :: M.Map (String, String) Integer
}
instance Default DState where
@@ -128,6 +131,7 @@ instance Default DState where
, docxMediaBag = mempty
, docxDropCap = mempty
, docxWarnings = []
+ , docxListState = M.empty
}
data DEnv = DEnv { docxOptions :: ReaderOptions
@@ -539,22 +543,25 @@ bodyPartToBlocks (Paragraph pPr parparts)
then return mempty
else return $ parStyleToTransform pPr $ para ils'
bodyPartToBlocks (ListItem pPr numId lvl (Just levelInfo) parparts) = do
- let
- kvs = case levelInfo of
- (_, fmt, txt, Just start) -> [ ("level", lvl)
- , ("num-id", numId)
- , ("format", fmt)
- , ("text", txt)
- , ("start", show start)
- ]
-
- (_, fmt, txt, Nothing) -> [ ("level", lvl)
- , ("num-id", numId)
- , ("format", fmt)
- , ("text", txt)
- ]
+ -- We check whether this current numId has previously been used,
+ -- since Docx expects us to pick up where we left off.
+ listState <- gets docxListState
+ let startFromState = M.lookup (numId, lvl) listState
+ (_, fmt,txt, startFromLevelInfo) = levelInfo
+ start = case startFromState of
+ Just n -> n + 1
+ Nothing -> case startFromLevelInfo of
+ Just n' -> n'
+ Nothing -> 1
+ kvs = [ ("level", lvl)
+ , ("num-id", numId)
+ , ("format", fmt)
+ , ("text", txt)
+ , ("start", show start)
+ ]
+ modify $ \st -> st{ docxListState = M.insert (numId, lvl) start listState}
blks <- bodyPartToBlocks (Paragraph pPr parparts)
- return $ divWith ("", ["list-item"], kvs) blks
+ return $ divWith ("", ["list-item"], kvs) blks
bodyPartToBlocks (ListItem pPr _ _ _ parparts) =
let pPr' = pPr {pStyle = "ListParagraph": pStyle pPr}
in
diff --git a/test/Tests/Readers/Docx.hs b/test/Tests/Readers/Docx.hs
index 421acaa8b..6d91c36ae 100644
--- a/test/Tests/Readers/Docx.hs
+++ b/test/Tests/Readers/Docx.hs
@@ -206,6 +206,14 @@ tests = [ testGroup "inlines"
"docx/lists.docx"
"docx/lists.native"
, testCompare
+ "lists continuing after interruption"
+ "docx/lists_continuing.docx"
+ "docx/lists_continuing.native"
+ , testCompare
+ "lists restarting after interruption"
+ "docx/lists_restarting.docx"
+ "docx/lists_restarting.native"
+ , testCompare
"definition lists"
"docx/definition_list.docx"
"docx/definition_list.native"
diff --git a/test/docx/lists_continuing.docx b/test/docx/lists_continuing.docx
new file mode 100644
index 000000000..e6249260b
--- /dev/null
+++ b/test/docx/lists_continuing.docx
Binary files differ
diff --git a/test/docx/lists_continuing.native b/test/docx/lists_continuing.native
new file mode 100644
index 000000000..24d352ce5
--- /dev/null
+++ b/test/docx/lists_continuing.native
@@ -0,0 +1,7 @@
+[OrderedList (1,Decimal,Period)
+ [[Para [Str "Foo"]]
+ ,[Para [Str "Bar"]]
+ ,[Para [Str "Baz"]]]
+,Para [Str "Interruption."]
+,OrderedList (4,Decimal,Period)
+ [[Para [Str "Bop"]]]]
diff --git a/test/docx/lists_restarting.docx b/test/docx/lists_restarting.docx
new file mode 100644
index 000000000..4acd67fcb
--- /dev/null
+++ b/test/docx/lists_restarting.docx
Binary files differ
diff --git a/test/docx/lists_restarting.native b/test/docx/lists_restarting.native
new file mode 100644
index 000000000..6602f1262
--- /dev/null
+++ b/test/docx/lists_restarting.native
@@ -0,0 +1,8 @@
+[OrderedList (2,Decimal,Period)
+ [[Para [Str "Foo"]]
+ ,[Para [Str "Bar"]]
+ ,[Para [Str "Baz"]]]
+,BlockQuote
+ [Para [Str "Interruption"]]
+,OrderedList (1,Decimal,Period)
+ [[Para [Str "Bop."]]]]