Skip to content

#8986 Image before Title still respects Title metadata #9162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/Text/Pandoc/Readers/Docx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import Control.Monad.State.Strict
import Data.Bifunctor (bimap, first)
import qualified Data.ByteString.Lazy as B
import Data.Default (Default)
import Data.List (delete, intersect, foldl')
import Data.List (partition, delete, intersect, foldl')
import Data.Char (isSpace)
import qualified Data.Map as M
import qualified Data.Text as T
Expand Down Expand Up @@ -177,7 +177,13 @@ metaStyles = M.fromList [ ("Title", "title")
, ("Abstract", "abstract")]

sepBodyParts :: [BodyPart] -> ([BodyPart], [BodyPart])
sepBodyParts = span (\bp -> isMetaPar bp || isEmptyPar bp)
sepBodyParts bps = (metaWithoutEmpty, nonMetaFirst ++ emptyPars ++ nonMetaLast)
where
(nonMetaFirst, rest) = break isMetaOrEmpty bps
(meta, nonMetaLast) = span isMetaOrEmpty rest
isMetaOrEmpty bp = isMetaPar bp || isEmptyPar bp

(metaWithoutEmpty, emptyPars) = partition (not . isEmptyPar) meta

isMetaPar :: BodyPart -> Bool
isMetaPar (Paragraph pPr _) =
Expand Down
4 changes: 4 additions & 0 deletions test/Tests/Readers/Docx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ tests = [ testGroup "document"
"i18n blocks (headers and blockquotes)"
"docx/i18n_blocks.docx"
"docx/i18n_blocks.native"
, testCompare
"Image before Title"
"docx/image-before-title.docx"
"docx/image-before-title.native"
, testCompare
"lists"
"docx/lists.docx"
Expand Down
234 changes: 182 additions & 52 deletions test/docx/0_level_headers.native
Original file line number Diff line number Diff line change
@@ -1,52 +1,182 @@
[Table ("",[],[]) (Caption Nothing
[])
[(AlignDefault,ColWidth 1.0)]
(TableHead ("",[],[])
[])
[(TableBody ("",[],[]) (RowHeadColumns 0)
[]
[Row ("",[],[])
[Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[]]
,Row ("",[],[])
[Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "User\8217s",Space,Str "Guide"]]]
,Row ("",[],[])
[Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[]]
,Row ("",[],[])
[Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[]]
,Row ("",[],[])
[Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[]]
,Row ("",[],[])
[Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "11",Space,Str "August",Space,Str "2017"]]]
,Row ("",[],[])
[Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[]]
,Row ("",[],[])
[Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[]]
,Row ("",[],[])
[Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[]]
,Row ("",[],[])
[Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[]]])]
(TableFoot ("",[],[])
[])
,Para [Str "CONTENTS"]
,Para [Strong [Str "Section",Space,Str "Page"]]
,Para [Str "FIGURES",Space,Link ("",[],[]) [Str "iv"] ("#figures","")]
,Para [Str "TABLES",Space,Link ("",[],[]) [Str "v"] ("#tables","")]
,Para [Str "SECTION",Space,Str "1",Space,Str "Introduction",Space,Link ("",[],[]) [Str "2"] ("#introduction","")]
,Header 1 ("figures",["Heading-0"],[]) [Str "FIGURES"]
,Para [Strong [Str "Figure",Space,Str "Page"]]
,Para [Strong [Str "No",Space,Str "table",Space,Str "of",Space,Str "figures",Space,Str "entries",Space,Str "found."]]
,Header 1 ("tables",["Heading-0"],[]) [Str "TABLES"]
,Para [Strong [Str "Table",Space,Str "Page"]]
,Para [Strong [Str "No",Space,Str "table",Space,Str "of",Space,Str "figures",Space,Str "entries",Space,Str "found."]]
,Header 1 ("introduction",[],[]) [Str "Introduction"]
,Para [Str "Nothing",Space,Str "to",Space,Str "introduce,",Space,Str "yet."]]
Pandoc
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2023-10-31 at 14 27 39

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what to do with this. It is entirely logical this is being converted to a Title (meta) so I would prefer letting that meaning just sit in there and maybe change the example.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain more fully? Are you saying that the Title style is used for both the document title and the title of the table of contents section?

Meta
{ unMeta =
fromList [ ( "title" , MetaInlines [ Str "CONTENTS" ] ) ]
}
[ Table
( "" , [] , [] )
(Caption Nothing [])
[ ( AlignDefault , ColWidth 1.0 ) ]
(TableHead ( "" , [] , [] ) [])
[ TableBody
( "" , [] , [] )
(RowHeadColumns 0)
[]
[ Row
( "" , [] , [] )
[ Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[]
]
, Row
( "" , [] , [] )
[ Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[ Plain [ Str "User\8217s" , Space , Str "Guide" ] ]
]
, Row
( "" , [] , [] )
[ Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[]
]
, Row
( "" , [] , [] )
[ Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[]
]
, Row
( "" , [] , [] )
[ Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[]
]
, Row
( "" , [] , [] )
[ Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[ Plain
[ Str "11"
, Space
, Str "August"
, Space
, Str "2017"
]
]
]
, Row
( "" , [] , [] )
[ Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[]
]
, Row
( "" , [] , [] )
[ Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[]
]
, Row
( "" , [] , [] )
[ Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[]
]
, Row
( "" , [] , [] )
[ Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[]
]
]
]
(TableFoot ( "" , [] , [] ) [])
, Para [ Strong [ Str "Section" , Space , Str "Page" ] ]
, Para
[ Str "FIGURES"
, Space
, Link ( "" , [] , [] ) [ Str "iv" ] ( "#figures" , "" )
]
, Para
[ Str "TABLES"
, Space
, Link ( "" , [] , [] ) [ Str "v" ] ( "#tables" , "" )
]
, Para
[ Str "SECTION"
, Space
, Str "1"
, Space
, Str "Introduction"
, Space
, Link ( "" , [] , [] ) [ Str "2" ] ( "#introduction" , "" )
]
, Header
1 ( "figures" , [ "Heading-0" ] , [] ) [ Str "FIGURES" ]
, Para [ Strong [ Str "Figure" , Space , Str "Page" ] ]
, Para
[ Strong
[ Str "No"
, Space
, Str "table"
, Space
, Str "of"
, Space
, Str "figures"
, Space
, Str "entries"
, Space
, Str "found."
]
]
, Header
1 ( "tables" , [ "Heading-0" ] , [] ) [ Str "TABLES" ]
, Para [ Strong [ Str "Table" , Space , Str "Page" ] ]
, Para
[ Strong
[ Str "No"
, Space
, Str "table"
, Space
, Str "of"
, Space
, Str "figures"
, Space
, Str "entries"
, Space
, Str "found."
]
]
, Header
1 ( "introduction" , [] , [] ) [ Str "Introduction" ]
, Para
[ Str "Nothing"
, Space
, Str "to"
, Space
, Str "introduce,"
, Space
, Str "yet."
]
]
Binary file added test/docx/image-before-title.docx
Binary file not shown.
97 changes: 97 additions & 0 deletions test/docx/image-before-title.native
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
Pandoc
Meta
{ unMeta =
fromList
[ ( "subtitle"
, MetaInlines
[ Str "This"
, Space
, Str "is"
, Space
, Str "a"
, Space
, Str "subtitle"
]
)
, ( "title"
, MetaInlines
[ Str "This"
, Space
, Str "is"
, Space
, Str "a"
, Space
, Str "title"
]
)
]
}
[ Para
[ Image
( ""
, []
, [ ( "width" , "6.268055555555556in" )
, ( "height" , "6.268055555555556in" )
]
)
[ Str "A"
, Space
, Str "cat"
, Space
, Str "holding"
, Space
, Str "a"
, Space
, Str "rainbow"
, Space
, Str "flag."
]
( "media/image1.jpeg" , "" )
]
, Header
1
( "this-is-a-heading-1" , [] , [] )
[ Str "This"
, Space
, Str "is"
, Space
, Str "a"
, Space
, Str "heading"
, Space
, Str "1"
]
, Para
[ Str "This"
, Space
, Str "is"
, Space
, Str "some"
, Space
, Str "text."
]
, Header
2
( "this-is-a-heading-2" , [] , [] )
[ Str "This"
, Space
, Str "is"
, Space
, Str "a"
, Space
, Str "heading"
, Space
, Str "2"
]
, Para
[ Str "This"
, Space
, Str "is"
, Space
, Str "also"
, Space
, Str "some"
, Space
, Str "text."
]
]