From 7d3e7a5a6d9e7b139fd15e10a52b85f87aba42b1 Mon Sep 17 00:00:00 2001 From: Jesse Rosenthal Date: Wed, 28 Feb 2018 16:27:18 -0500 Subject: Docx reader: Handle nested sdt tags. Previously we had only unwrapped one level of sdt tags. Now we recurse if we find them. Closes: #4415 --- src/Text/Pandoc/Readers/Docx/Parse.hs | 2 +- test/Tests/Readers/Docx.hs | 4 ++++ test/docx/nested_sdt.docx | Bin 0 -> 11694 bytes test/docx/nested_sdt.native | 3 +++ 4 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 test/docx/nested_sdt.docx create mode 100644 test/docx/nested_sdt.native diff --git a/src/Text/Pandoc/Readers/Docx/Parse.hs b/src/Text/Pandoc/Readers/Docx/Parse.hs index c123a0018..1f7f07e36 100644 --- a/src/Text/Pandoc/Readers/Docx/Parse.hs +++ b/src/Text/Pandoc/Readers/Docx/Parse.hs @@ -136,7 +136,7 @@ unwrapSDT :: NameSpaces -> Content -> [Content] unwrapSDT ns (Elem element) | isElem ns "w" "sdt" element , Just sdtContent <- findChildByName ns "w" "sdtContent" element - = map Elem $ elChildren sdtContent + = concatMap (unwrapSDT ns) $ map Elem $ elChildren sdtContent unwrapSDT _ content = [content] unwrapSDTchild :: NameSpaces -> Content -> Content diff --git a/test/Tests/Readers/Docx.hs b/test/Tests/Readers/Docx.hs index cef80d6d1..0ba765c93 100644 --- a/test/Tests/Readers/Docx.hs +++ b/test/Tests/Readers/Docx.hs @@ -178,6 +178,10 @@ tests = [ testGroup "inlines" "inlines inside of Structured Document Tags" "docx/sdt_elements.docx" "docx/sdt_elements.native" + , testCompare + "nested Structured Document Tags" + "docx/nested_sdt.docx" + "docx/nested_sdt.native" , testCompare "remove anchor spans with nothing pointing to them" "docx/unused_anchors.docx" diff --git a/test/docx/nested_sdt.docx b/test/docx/nested_sdt.docx new file mode 100644 index 000000000..1a0827db3 Binary files /dev/null and b/test/docx/nested_sdt.docx differ diff --git a/test/docx/nested_sdt.native b/test/docx/nested_sdt.native new file mode 100644 index 000000000..d0adc05ac --- /dev/null +++ b/test/docx/nested_sdt.native @@ -0,0 +1,3 @@ +[Para [Str "Test",Space,Str "Paragraph1"] +,Para [Str "Test",Space,Str "Paragraph2"] +,Para [Str "Test",Space,Str "Paragraph3"]] -- cgit v1.2.3