From 4fc3f511863c578be6a3237d02133da25db0ce05 Mon Sep 17 00:00:00 2001 From: Jesse Rosenthal Date: Sat, 30 Dec 2017 08:21:42 -0500 Subject: Docx reader: Read multiple children of w:sdtContents` Previously we had only read the first child of an sdtContents tag. Now we replace sdt with all children of the sdtContents tag. This changes the expected test result of our nested_anchors test, since now we read docx's generated TOCs. --- src/Text/Pandoc/Readers/Docx/Parse.hs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/Text/Pandoc/Readers/Docx') diff --git a/src/Text/Pandoc/Readers/Docx/Parse.hs b/src/Text/Pandoc/Readers/Docx/Parse.hs index 48a512be2..071f901b6 100644 --- a/src/Text/Pandoc/Readers/Docx/Parse.hs +++ b/src/Text/Pandoc/Readers/Docx/Parse.hs @@ -118,17 +118,21 @@ mapD f xs = in concatMapM handler xs -unwrapSDT :: NameSpaces -> Content -> Content +unwrapSDT :: NameSpaces -> Content -> [Content] unwrapSDT ns (Elem element) | isElem ns "w" "sdt" element , Just sdtContent <- findChildByName ns "w" "sdtContent" element - , child : _ <- elChildren sdtContent - = Elem child -unwrapSDT _ content = content + = map Elem $ elChildren sdtContent +unwrapSDT _ content = [content] + +unwrapSDTchild :: NameSpaces -> Content -> Content +unwrapSDTchild ns (Elem element) = + Elem $ element { elContent = concatMap (unwrapSDT ns) (elContent element) } +unwrapSDTchild _ content = content walkDocument' :: NameSpaces -> XMLC.Cursor -> XMLC.Cursor walkDocument' ns cur = - let modifiedCur = XMLC.modifyContent (unwrapSDT ns) cur + let modifiedCur = XMLC.modifyContent (unwrapSDTchild ns) cur in case XMLC.nextDF modifiedCur of Just cur' -> walkDocument' ns cur' -- cgit v1.2.3