git.iko.soy/typeable/pandoc
on master help sign in
Markdown reader: Fixed bug with headerless grid tables.

The 1.10 code assumed that each table header cell contains exactly one block. That failed for headerless tables (0) and also for tables with multiple blocks in a header cell. The code is fixed and tests provided. Thanks to Andrew Lee for pointing out the bug.

commitaf849537819885694cc4487056721480ab21067d authorJohn MacFarlane <fiddlosopher@gmail.com> dateMon 21 Jan 2013, 09:50 (14 years ago) parentc4b93bc
3 files changed+93−3
src/Text/Pandoc/Readers/Markdown.hs+2−2 tests/markdown-reader-more.native+52−1 tests/markdown-reader-more.txt+39
src/Text/Pandoc/Readers/Markdown.hs+2−2
@@ -1110,7 +1110,7 @@ gridTableHeader headless = try $ do
11101110 then replicate (length dashes) ""
11111111 else map (intercalate " ") $ transpose
11121112 $ map (gridTableSplitLine indices) rawContent
1113− heads <- fmap sequence $ mapM (parseFromString block) $
1113+ heads <- fmap sequence $ mapM (parseFromString parseBlocks) $
11141114 map trim rawHeads
11151115 return (heads, aligns, indices)
11161116
@@ -1127,7 +1127,7 @@ gridTableRow indices = do
11271127 colLines <- many1 (gridTableRawLine indices)
11281128 let cols = map ((++ "\n") . unlines . removeOneLeadingSpace) $
11291129 transpose colLines
1130− fmap compactify' <$> fmap sequence (mapM (parseFromString block) cols)
1130+ fmap compactify' <$> fmap sequence (mapM (parseFromString parseBlocks) cols)
11311131
11321132removeOneLeadingSpace :: [String] -> [String]
11331133removeOneLeadingSpace xs =
tests/markdown-reader-more.native+52−1
@@ -67,4 +67,55 @@
6767,Header 2 ("foobar",["baz"],[("key","val")]) [Str "Explicit",Space,Str "header",Space,Str "attributes"]
6868,Header 2 ("line-blocks",[],[]) [Str "Line",Space,Str "blocks"]
6969,Para [Str "But",Space,Str "can",Space,Str "a",Space,Str "bee",Space,Str "be",Space,Str "said",Space,Str "to",Space,Str "be",LineBreak,Str "\160\160\160\160or",Space,Str "not",Space,Str "to",Space,Str "be",Space,Str "an",Space,Str "entire",Space,Str "bee,",LineBreak,Str "\160\160\160\160\160\160\160\160when",Space,Str "half",Space,Str "the",Space,Str "bee",Space,Str "is",Space,Str "not",Space,Str "a",Space,Str "bee,",LineBreak,Str "\160\160\160\160\160\160\160\160\160\160\160\160due",Space,Str "to",Space,Str "some",Space,Str "ancient",Space,Str "injury?"]
70−,Para [Str "Continuation",Space,Str "line",LineBreak,Str "\160\160and",Space,Str "another"]]
70+,Para [Str "Continuation",Space,Str "line",LineBreak,Str "\160\160and",Space,Str "another"]
71+,Header 2 ("grid-tables",[],[]) [Str "Grid",Space,Str "Tables"]
72+,Table [] [AlignDefault,AlignDefault,AlignDefault] [0.2638888888888889,0.16666666666666666,0.18055555555555555]
73+ [[Plain [Str "col",Space,Str "1"]]
74+ ,[Plain [Str "col",Space,Str "2"]]
75+ ,[Plain [Str "col",Space,Str "3"]]]
76+ [[[Para [Str "r1",Space,Str "a",Space,Str "r1",Space,Str "bis"]]
77+ ,[Para [Str "b",Space,Str "b",Space,Str "2"]]
78+ ,[Para [Str "c",Space,Str "c",Space,Str "2"]]]
79+ ,[[Para [Str "r2",Space,Str "d"]]
80+ ,[Para [Str "e"]]
81+ ,[Para [Str "f"]]]]
82+,Para [Str "Headless"]
83+,Table [] [AlignDefault,AlignDefault,AlignDefault] [0.2638888888888889,0.16666666666666666,0.18055555555555555]
84+ [[]
85+ ,[]
86+ ,[]]
87+ [[[Para [Str "r1",Space,Str "a",Space,Str "r1",Space,Str "bis"]]
88+ ,[Para [Str "b",Space,Str "b",Space,Str "2"]]
89+ ,[Para [Str "c",Space,Str "c",Space,Str "2"]]]
90+ ,[[Para [Str "r2",Space,Str "d"]]
91+ ,[Para [Str "e"]]
92+ ,[Para [Str "f"]]]]
93+,Para [Str "Spaces",Space,Str "at",Space,Str "ends",Space,Str "of",Space,Str "lines"]
94+,Table [] [AlignDefault,AlignDefault,AlignDefault] [0.2638888888888889,0.16666666666666666,0.18055555555555555]
95+ [[]
96+ ,[]
97+ ,[]]
98+ [[[Para [Str "r1",Space,Str "a",Space,Str "r1",Space,Str "bis"]]
99+ ,[Para [Str "b",Space,Str "b",Space,Str "2"]]
100+ ,[Para [Str "c",Space,Str "c",Space,Str "2"]]]
101+ ,[[Para [Str "r2",Space,Str "d"]]
102+ ,[Para [Str "e"]]
103+ ,[Para [Str "f"]]]]
104+,Para [Str "Multiple",Space,Str "blocks",Space,Str "in",Space,Str "a",Space,Str "cell"]
105+,Table [] [AlignDefault,AlignDefault,AlignDefault] [0.2638888888888889,0.16666666666666666,0.18055555555555555]
106+ [[]
107+ ,[]
108+ ,[]]
109+ [[[Header 1 ("col-1",[],[]) [Str "col",Space,Str "1"]
110+ ,Para [Str "col",Space,Str "1"]]
111+ ,[Header 1 ("col-2",[],[]) [Str "col",Space,Str "2"]
112+ ,Para [Str "col",Space,Str "2"]]
113+ ,[Header 1 ("col-3",[],[]) [Str "col",Space,Str "3"]
114+ ,Para [Str "col",Space,Str "3"]]]
115+ ,[[Para [Str "r1",Space,Str "a"]
116+ ,Para [Str "r1",Space,Str "bis"]]
117+ ,[BulletList
118+ [[Plain [Str "b"]]
119+ ,[Plain [Str "b",Space,Str "2"]]
120+ ,[Plain [Str "b",Space,Str "2"]]]]
121+ ,[Para [Str "c",Space,Str "c",Space,Str "2",Space,Str "c",Space,Str "2"]]]]]
tests/markdown-reader-more.txt+39
@@ -162,3 +162,42 @@ But this is not a link to [My other header], since the reference is defined.
162162| and
163163 another
164164
165+## Grid Tables
166+
167++------------------+-----------+------------+
168+| col 1 | col 2 | col 3 |
169++==================+===========+============+
170+| r1 a | b | c |
171+| r1 bis | b 2 | c 2 |
172++------------------+-----------+------------+
173+| r2 d | e | f |
174++------------------+-----------+------------+
175+
176+Headless
177+
178++------------------+-----------+------------+
179+| r1 a | b | c |
180+| r1 bis | b 2 | c 2 |
181++------------------+-----------+------------+
182+| r2 d | e | f |
183++------------------+-----------+------------+
184+
185+Spaces at ends of lines
186+
187++------------------+-----------+------------+
188+| r1 a | b | c |
189+| r1 bis | b 2 | c 2 |
190++------------------+-----------+------------+
191+| r2 d | e | f |
192++------------------+-----------+------------+
193+
194+Multiple blocks in a cell
195+
196++------------------+-----------+------------+
197+| # col 1 | # col 2 | # col 3 |
198+| col 1 | col 2 | col 3 |
199++------------------+-----------+------------+
200+| r1 a | - b | c |
201+| | - b 2 | c 2 |
202+| r1 bis | - b 2 | c 2 |
203++------------------+-----------+------------+