git.iko.soy/typeable/pandoc
on master help sign in
HTML writer: support intermediate table headers

Closes: #6314

commit34151e8da8e1863b7954d87c1713b97f3a944545 authorAlbert Krewinkel <albert@zeitkraut.de> dateSun 13 Sep 2020, 23:20 (6 years ago) parent62948f3
5 files changed+158−5
src/Text/Pandoc/Writers/HTML.hs+10−4 test/Tests/Old.hs+1−1 test/tables/students.html4+55 test/tables/students.html5+55 test/tables/students.native+37
src/Text/Pandoc/Writers/HTML.hs+10−4
@@ -919,7 +919,7 @@ tableToHtml opts (Ann.Table attr caption colspecs thead tbodies tfoot) = do
919919 nl opts
920920 coltags <- colSpecListToHtml opts colspecs
921921 head' <- tableHeadToHtml opts thead
922− body' <- mconcat <$> mapM (tableBodyToHtml opts) tbodies
922+ bodies <- intersperse (nl opts) <$> mapM (tableBodyToHtml opts) tbodies
923923 foot' <- tableFootToHtml opts tfoot
924924 let (ident,classes,kvs) = attr
925925 -- When widths of columns are < 100%, we need to set width for the whole
@@ -940,7 +940,7 @@ tableToHtml opts (Ann.Table attr caption colspecs thead tbodies tfoot) = do
940940 captionDoc
941941 coltags
942942 head'
943− body'
943+ mconcat bodies
944944 foot'
945945 nl opts
946946
@@ -948,8 +948,14 @@ tableBodyToHtml :: PandocMonad m
948948 => WriterOptions
949949 -> Ann.TableBody
950950 -> StateT WriterState m Html
951−tableBodyToHtml opts (Ann.TableBody attr _rowHeadCols _intm rows) =
952− addAttrs opts attr . H.tbody =<< bodyRowsToHtml opts rows
951+tableBodyToHtml opts (Ann.TableBody attr _rowHeadCols inthead rows) =
952+ addAttrs opts attr . H.tbody =<< do
953+ intermediateHead <-
954+ if null inthead
955+ then return mempty
956+ else headerRowsToHtml opts Thead inthead
957+ bodyRows <- bodyRowsToHtml opts rows
958+ return $ intermediateHead <> bodyRows
953959
954960tableHeadToHtml :: PandocMonad m
955961 => WriterOptions
test/Tests/Old.hs+1−1
@@ -272,7 +272,7 @@ extendedWriterTests pandocPath format
272272 opts
273273 ("tables" </> name <.> "native")
274274 ("tables" </> name <.> format)
275− in map testForTable ["planets", "nordics"]
275+ in map testForTable ["planets", "nordics", "students"]
276276 where
277277 opts = ["-r", "native", "-w", format, "--columns=78",
278278 "--variable", "pandoc-version="]
test/tables/students.html4new file+55
@@ -0,0 +1,55 @@
1+<table id="students" source="mdn">
2+<caption><p>List of Students</p></caption>
3+<colgroup>
4+<col width="50%" />
5+<col width="50%" />
6+</colgroup>
7+<thead>
8+<tr class="header">
9+<th align="center">Student ID</th>
10+<th align="center">Name</th>
11+</tr>
12+</thead>
13+<tbody class="souvereign-states">
14+<tr class="odd">
15+<th align="left" colspan="2">Computer Science</th>
16+</tr>
17+
18+<tr class="odd">
19+<td align="left">3741255</td>
20+<td align="left">Jones, Martha</td>
21+</tr>
22+<tr class="even">
23+<td align="left">4077830</td>
24+<td align="left">Pierce, Benjamin</td>
25+</tr>
26+<tr class="odd">
27+<td align="left">5151701</td>
28+<td align="left">Kirk, James</td>
29+</tr>
30+</tbody>
31+<tbody>
32+<tr class="odd">
33+<th align="left" colspan="2">Russian Literature</th>
34+</tr>
35+
36+<tr class="odd">
37+<td align="left">3971244</td>
38+<td align="left">Nim, Victor</td>
39+</tr>
40+</tbody>
41+<tbody>
42+<tr class="odd">
43+<th align="left" colspan="2">Astrophysics</th>
44+</tr>
45+
46+<tr class="odd">
47+<td align="left">4100332</td>
48+<td align="left">Petrov, Alexandra</td>
49+</tr>
50+<tr class="even">
51+<td align="left">4100332</td>
52+<td align="left">Toyota, Hiroko</td>
53+</tr>
54+</tbody>
55+</table>
test/tables/students.html5new file+55
@@ -0,0 +1,55 @@
1+<table id="students" data-source="mdn">
2+<caption><p>List of Students</p></caption>
3+<colgroup>
4+<col style="width: 50%" />
5+<col style="width: 50%" />
6+</colgroup>
7+<thead>
8+<tr class="header">
9+<th style="text-align: center;">Student ID</th>
10+<th style="text-align: center;">Name</th>
11+</tr>
12+</thead>
13+<tbody class="souvereign-states">
14+<tr class="odd">
15+<th style="text-align: left;" colspan="2">Computer Science</th>
16+</tr>
17+
18+<tr class="odd">
19+<td style="text-align: left;">3741255</td>
20+<td style="text-align: left;">Jones, Martha</td>
21+</tr>
22+<tr class="even">
23+<td style="text-align: left;">4077830</td>
24+<td style="text-align: left;">Pierce, Benjamin</td>
25+</tr>
26+<tr class="odd">
27+<td style="text-align: left;">5151701</td>
28+<td style="text-align: left;">Kirk, James</td>
29+</tr>
30+</tbody>
31+<tbody>
32+<tr class="odd">
33+<th style="text-align: left;" colspan="2">Russian Literature</th>
34+</tr>
35+
36+<tr class="odd">
37+<td style="text-align: left;">3971244</td>
38+<td style="text-align: left;">Nim, Victor</td>
39+</tr>
40+</tbody>
41+<tbody>
42+<tr class="odd">
43+<th style="text-align: left;" colspan="2">Astrophysics</th>
44+</tr>
45+
46+<tr class="odd">
47+<td style="text-align: left;">4100332</td>
48+<td style="text-align: left;">Petrov, Alexandra</td>
49+</tr>
50+<tr class="even">
51+<td style="text-align: left;">4100332</td>
52+<td style="text-align: left;">Toyota, Hiroko</td>
53+</tr>
54+</tbody>
55+</table>
test/tables/students.nativenew file+37
@@ -0,0 +1,37 @@
1+[Table ("students",[],[("source","mdn")]) (Caption Nothing
2+ [Para [Str "List", Space, Str "of", Space, Str "Students"]])
3+ [(AlignLeft,ColWidth 0.5)
4+ ,(AlignLeft,ColWidth 0.5)]
5+ (TableHead ("",[],[])
6+ [Row ("",[],[])
7+ [Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Plain [Str "Student", Space, Str "ID"]]
8+ ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Plain [Str "Name"]]]])
9+ [TableBody ("",["souvereign-states"],[]) (RowHeadColumns 0)
10+ [Row ("",[],[])
11+ [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 2) [Plain [Str "Computer", Space, Str "Science"]]]]
12+ [Row ("",[],[])
13+ [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "3741255"]]
14+ ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "Jones,", Space, Str "Martha"]]]
15+ ,Row ("",[],[])
16+ [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "4077830"]]
17+ ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "Pierce,", Space, Str "Benjamin"]]]
18+ ,Row ("",[],[])
19+ [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "5151701"]]
20+ ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "Kirk,", Space, Str "James"]]]]
21+ ,TableBody ("",[],[]) (RowHeadColumns 0)
22+ [Row ("",[],[])
23+ [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 2) [Plain [Str "Russian", Space, Str "Literature"]]]]
24+ [Row ("",[],[])
25+ [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "3971244"]]
26+ ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "Nim,", Space, Str "Victor"]]]]
27+ ,TableBody ("",[],[]) (RowHeadColumns 0)
28+ [Row ("",[],[])
29+ [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 2) [Plain [Str "Astrophysics"]]]]
30+ [Row ("",[],[])
31+ [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "4100332"]]
32+ ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "Petrov,", Space, Str "Alexandra"]]]
33+ ,Row ("",[],[])
34+ [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "4100332"]]
35+ ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "Toyota,", Space, Str "Hiroko"]]]]]
36+ (TableFoot ("",[],[]) [])
37+]