git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #1577 from jkr/plainCells

Plain cells

commit608e402802823e9f09fd3b7c294d23f166881817 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 28 Aug 2014, 13:10 (12 years ago) parentc7f47d73b5a868
3 files changed+42−21
src/Text/Pandoc/Readers/Docx.hs+12−1 tests/docx/tables.docx tests/docx/tables.native+30−20
src/Text/Pandoc/Readers/Docx.hs+12−1
@@ -95,6 +95,7 @@ import Control.Monad.Reader
9595import Control.Monad.State
9696import Control.Applicative ((<$>))
9797import Data.Sequence (ViewL(..), viewl)
98+import qualified Data.Sequence as Seq (null)
9899
99100readDocx :: ReaderOptions
100101 -> B.ByteString
@@ -391,11 +392,21 @@ makeHeaderAnchor' (Header n (_, classes, kvs) ils) =
391392 return $ Header n (newIdent, classes, kvs) ils
392393makeHeaderAnchor' blk = return blk
393394
395+-- Rewrite a standalone paragraph block as a plain
396+singleParaToPlain :: Blocks -> Blocks
397+singleParaToPlain blks
398+ | (Para (ils) :< seeq) <- viewl $ unMany blks
399+ , Seq.null seeq =
400+ singleton $ Plain ils
401+singleParaToPlain blks = blks
402+
394403cellToBlocks :: Cell -> DocxContext Blocks
395404cellToBlocks (Cell bps) = concatReduce <$> mapM bodyPartToBlocks bps
396405
397406rowToBlocksList :: Row -> DocxContext [Blocks]
398−rowToBlocksList (Row cells) = mapM cellToBlocks cells
407+rowToBlocksList (Row cells) = do
408+ blksList <- mapM cellToBlocks cells
409+ return $ map singleParaToPlain blksList
399410
400411trimLineBreaks :: [Inline] -> [Inline]
401412trimLineBreaks [] = []
tests/docx/tables.docx

Binary file not shown.

tests/docx/tables.native+30−20
@@ -1,24 +1,34 @@
11[Header 2 ("a-table-with-and-without-a-header-row",[],[]) [Str "A",Space,Str "table,",Space,Str "with",Space,Str "and",Space,Str "without",Space,Str "a",Space,Str "header",Space,Str "row"]
22,Table [] [AlignDefault,AlignDefault,AlignDefault,AlignDefault] [0.0,0.0,0.0,0.0]
3− [[Para [Str "Name"]]
4− ,[Para [Str "Game"]]
5− ,[Para [Str "Fame"]]
6− ,[Para [Str "Blame"]]]
7− [[[Para [Str "Lebron",Space,Str "James"]]
8− ,[Para [Str "Basketball"]]
9− ,[Para [Str "Very",Space,Str "High"]]
10− ,[Para [Str "Leaving",Space,Str "Cleveland"]]]
11− ,[[Para [Str "Ryan",Space,Str "Braun"]]
12− ,[Para [Str "Baseball"]]
13− ,[Para [Str "Moderate"]]
14− ,[Para [Str "Steroids"]]]
15− ,[[Para [Str "Russell",Space,Str "Wilson"]]
16− ,[Para [Str "Football"]]
17− ,[Para [Str "High"]]
18− ,[Para [Str "Tacky",Space,Str "uniform"]]]]
3+ [[Plain [Str "Name"]]
4+ ,[Plain [Str "Game"]]
5+ ,[Plain [Str "Fame"]]
6+ ,[Plain [Str "Blame"]]]
7+ [[[Plain [Str "Lebron",Space,Str "James"]]
8+ ,[Plain [Str "Basketball"]]
9+ ,[Plain [Str "Very",Space,Str "High"]]
10+ ,[Plain [Str "Leaving",Space,Str "Cleveland"]]]
11+ ,[[Plain [Str "Ryan",Space,Str "Braun"]]
12+ ,[Plain [Str "Baseball"]]
13+ ,[Plain [Str "Moderate"]]
14+ ,[Plain [Str "Steroids"]]]
15+ ,[[Plain [Str "Russell",Space,Str "Wilson"]]
16+ ,[Plain [Str "Football"]]
17+ ,[Plain [Str "High"]]
18+ ,[Plain [Str "Tacky",Space,Str "uniform"]]]]
1919,Table [] [AlignDefault,AlignDefault] [0.0,0.0]
2020 []
21− [[[Para [Str "Sinple"]]
22− ,[Para [Str "Table"]]]
23− ,[[Para [Str "Without"]]
24− ,[Para [Str "Header"]]]]]
21+ [[[Plain [Str "Sinple"]]
22+ ,[Plain [Str "Table"]]]
23+ ,[[Plain [Str "Without"]]
24+ ,[Plain [Str "Header"]]]]
25+,Table [] [AlignDefault,AlignDefault] [0.0,0.0]
26+ []
27+ [[[Para [Str "Simple"]
28+ ,Para [Str "Multiparagraph"]]
29+ ,[Para [Str "Table"]
30+ ,Para [Str "Full"]]]
31+ ,[[Para [Str "Of"]
32+ ,Para [Str "Paragraphs"]]
33+ ,[Para [Str "In",Space,Str "each"]
34+ ,Para [Str "Cell."]]]]]