diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index 4ab40f5a61ec..1e64a114d871 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -177,7 +177,36 @@ metaStyles = M.fromList [ ("Title", "title") , ("Abstract", "abstract")] sepBodyParts :: [BodyPart] -> ([BodyPart], [BodyPart]) -sepBodyParts = span (\bp -> isMetaPar bp || isEmptyPar bp) +sepBodyParts = span seperator + where + -- | Meta is either empty, specifically has a meta style, but never is exclusively + -- containing visuals. + seperator :: BodyPart -> Bool + seperator par = isEmptyPar par || (isMetaPar par && not (isVisualBodyPart par)) + +isVisualBodyPart :: BodyPart -> Bool +isVisualBodyPart (Paragraph _ []) = False +isVisualBodyPart (Paragraph _ pps) = isVisualParParts pps +isVisualBodyPart _ = False + +isVisualParParts :: [ParPart] -> Bool +isVisualParParts = all isVisualParPart + +isVisualParPart :: ParPart -> Bool +isVisualParPart (Field _ pps) = isVisualParParts pps +isVisualParPart (PlainRun run) = isVisualRun run +isVisualParPart Drawing{} = True +isVisualParPart Chart = True +isVisualParPart Diagram = True +isVisualParPart PlainOMath{} = True +isVisualParPart OMathPara{} = True +isVisualParPart _ = False + +isVisualRun :: Run -> Bool +isVisualRun InlineDrawing{} = True +isVisualRun InlineDiagram{} = True +isVisualRun InlineChart{} = True +isVisualRun _ = False isMetaPar :: BodyPart -> Bool isMetaPar (Paragraph pPr _) = diff --git a/test/Tests/Readers/Docx.hs b/test/Tests/Readers/Docx.hs index d9935967f6c2..b51893ae9b23 100644 --- a/test/Tests/Readers/Docx.hs +++ b/test/Tests/Readers/Docx.hs @@ -265,6 +265,10 @@ tests = [ testGroup "document" "i18n blocks (headers and blockquotes)" "docx/i18n_blocks.docx" "docx/i18n_blocks.native" + , testCompare + "Image as Title" + "docx/image-as-title.docx" + "docx/image-as-title.native" , testCompare "lists" "docx/lists.docx" diff --git a/test/docx/image-as-title.docx b/test/docx/image-as-title.docx new file mode 100644 index 000000000000..8e2f1a20c896 Binary files /dev/null and b/test/docx/image-as-title.docx differ diff --git a/test/docx/image-as-title.native b/test/docx/image-as-title.native new file mode 100644 index 000000000000..433f96374d70 --- /dev/null +++ b/test/docx/image-as-title.native @@ -0,0 +1,37 @@ +[ Para + [ Image + ( "" + , [] + , [ ( "width" , "6.268055555555556in" ) + , ( "height" , "6.268055555555556in" ) + ] + ) + [] + ( "media/image1.png" , "" ) + ] + , Para + [ Str "An" + , Space + , Str "Image" + , Space + , Str "as" + , Space + , Str "a" + , Space + , Str "title" + , Space + , Str "should" + , Space + , Str "be" + , Space + , Str "downgraded" + , Space + , Str "to" + , Space + , Str "a" + , Space + , Str "normal" + , Space + , Str "paragraph!" + ] + ]