Skip to content

Commit

Permalink
\jgm#8986 fix bug of meta by splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanMeijer committed Oct 31, 2023
1 parent 156180b commit a87f67e
Show file tree
Hide file tree
Showing 3 changed files with 286 additions and 140 deletions.
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
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
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."
]
]
Loading

0 comments on commit a87f67e

Please sign in to comment.