diff options
-rw-r--r-- | src/Text/Pandoc/Writers/HTML.hs | 14 | ||||
-rw-r--r-- | test/Tests/Old.hs | 2 | ||||
-rw-r--r-- | test/tables/students.html4 | 55 | ||||
-rw-r--r-- | test/tables/students.html5 | 55 | ||||
-rw-r--r-- | test/tables/students.native | 37 |
5 files changed, 158 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index 9e6e22283..8162da66a 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -919,7 +919,7 @@ tableToHtml opts (Ann.Table attr caption colspecs thead tbodies tfoot) = do nl opts coltags <- colSpecListToHtml opts colspecs head' <- tableHeadToHtml opts thead - body' <- mconcat <$> mapM (tableBodyToHtml opts) tbodies + bodies <- intersperse (nl opts) <$> mapM (tableBodyToHtml opts) tbodies foot' <- tableFootToHtml opts tfoot let (ident,classes,kvs) = attr -- 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 captionDoc coltags head' - body' + mconcat bodies foot' nl opts @@ -948,8 +948,14 @@ tableBodyToHtml :: PandocMonad m => WriterOptions -> Ann.TableBody -> StateT WriterState m Html -tableBodyToHtml opts (Ann.TableBody attr _rowHeadCols _intm rows) = - addAttrs opts attr . H.tbody =<< bodyRowsToHtml opts rows +tableBodyToHtml opts (Ann.TableBody attr _rowHeadCols inthead rows) = + addAttrs opts attr . H.tbody =<< do + intermediateHead <- + if null inthead + then return mempty + else headerRowsToHtml opts Thead inthead + bodyRows <- bodyRowsToHtml opts rows + return $ intermediateHead <> bodyRows tableHeadToHtml :: PandocMonad m => WriterOptions diff --git a/test/Tests/Old.hs b/test/Tests/Old.hs index fc5721edb..d1d27d9a5 100644 --- a/test/Tests/Old.hs +++ b/test/Tests/Old.hs @@ -272,7 +272,7 @@ extendedWriterTests pandocPath format opts ("tables" </> name <.> "native") ("tables" </> name <.> format) - in map testForTable ["planets", "nordics"] + in map testForTable ["planets", "nordics", "students"] where opts = ["-r", "native", "-w", format, "--columns=78", "--variable", "pandoc-version="] diff --git a/test/tables/students.html4 b/test/tables/students.html4 new file mode 100644 index 000000000..b02b0aba8 --- /dev/null +++ b/test/tables/students.html4 @@ -0,0 +1,55 @@ +<table id="students" source="mdn"> +<caption><p>List of Students</p></caption> +<colgroup> +<col width="50%" /> +<col width="50%" /> +</colgroup> +<thead> +<tr class="header"> +<th align="center">Student ID</th> +<th align="center">Name</th> +</tr> +</thead> +<tbody class="souvereign-states"> +<tr class="odd"> +<th align="left" colspan="2">Computer Science</th> +</tr> + +<tr class="odd"> +<td align="left">3741255</td> +<td align="left">Jones, Martha</td> +</tr> +<tr class="even"> +<td align="left">4077830</td> +<td align="left">Pierce, Benjamin</td> +</tr> +<tr class="odd"> +<td align="left">5151701</td> +<td align="left">Kirk, James</td> +</tr> +</tbody> +<tbody> +<tr class="odd"> +<th align="left" colspan="2">Russian Literature</th> +</tr> + +<tr class="odd"> +<td align="left">3971244</td> +<td align="left">Nim, Victor</td> +</tr> +</tbody> +<tbody> +<tr class="odd"> +<th align="left" colspan="2">Astrophysics</th> +</tr> + +<tr class="odd"> +<td align="left">4100332</td> +<td align="left">Petrov, Alexandra</td> +</tr> +<tr class="even"> +<td align="left">4100332</td> +<td align="left">Toyota, Hiroko</td> +</tr> +</tbody> +</table> diff --git a/test/tables/students.html5 b/test/tables/students.html5 new file mode 100644 index 000000000..af9e088fb --- /dev/null +++ b/test/tables/students.html5 @@ -0,0 +1,55 @@ +<table id="students" data-source="mdn"> +<caption><p>List of Students</p></caption> +<colgroup> +<col style="width: 50%" /> +<col style="width: 50%" /> +</colgroup> +<thead> +<tr class="header"> +<th style="text-align: center;">Student ID</th> +<th style="text-align: center;">Name</th> +</tr> +</thead> +<tbody class="souvereign-states"> +<tr class="odd"> +<th style="text-align: left;" colspan="2">Computer Science</th> +</tr> + +<tr class="odd"> +<td style="text-align: left;">3741255</td> +<td style="text-align: left;">Jones, Martha</td> +</tr> +<tr class="even"> +<td style="text-align: left;">4077830</td> +<td style="text-align: left;">Pierce, Benjamin</td> +</tr> +<tr class="odd"> +<td style="text-align: left;">5151701</td> +<td style="text-align: left;">Kirk, James</td> +</tr> +</tbody> +<tbody> +<tr class="odd"> +<th style="text-align: left;" colspan="2">Russian Literature</th> +</tr> + +<tr class="odd"> +<td style="text-align: left;">3971244</td> +<td style="text-align: left;">Nim, Victor</td> +</tr> +</tbody> +<tbody> +<tr class="odd"> +<th style="text-align: left;" colspan="2">Astrophysics</th> +</tr> + +<tr class="odd"> +<td style="text-align: left;">4100332</td> +<td style="text-align: left;">Petrov, Alexandra</td> +</tr> +<tr class="even"> +<td style="text-align: left;">4100332</td> +<td style="text-align: left;">Toyota, Hiroko</td> +</tr> +</tbody> +</table> diff --git a/test/tables/students.native b/test/tables/students.native new file mode 100644 index 000000000..13122ede2 --- /dev/null +++ b/test/tables/students.native @@ -0,0 +1,37 @@ +[Table ("students",[],[("source","mdn")]) (Caption Nothing + [Para [Str "List", Space, Str "of", Space, Str "Students"]]) + [(AlignLeft,ColWidth 0.5) + ,(AlignLeft,ColWidth 0.5)] + (TableHead ("",[],[]) + [Row ("",[],[]) + [Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Plain [Str "Student", Space, Str "ID"]] + ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) [Plain [Str "Name"]]]]) + [TableBody ("",["souvereign-states"],[]) (RowHeadColumns 0) + [Row ("",[],[]) + [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 2) [Plain [Str "Computer", Space, Str "Science"]]]] + [Row ("",[],[]) + [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "3741255"]] + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "Jones,", Space, Str "Martha"]]] + ,Row ("",[],[]) + [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "4077830"]] + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "Pierce,", Space, Str "Benjamin"]]] + ,Row ("",[],[]) + [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "5151701"]] + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "Kirk,", Space, Str "James"]]]] + ,TableBody ("",[],[]) (RowHeadColumns 0) + [Row ("",[],[]) + [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 2) [Plain [Str "Russian", Space, Str "Literature"]]]] + [Row ("",[],[]) + [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "3971244"]] + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "Nim,", Space, Str "Victor"]]]] + ,TableBody ("",[],[]) (RowHeadColumns 0) + [Row ("",[],[]) + [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 2) [Plain [Str "Astrophysics"]]]] + [Row ("",[],[]) + [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "4100332"]] + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "Petrov,", Space, Str "Alexandra"]]] + ,Row ("",[],[]) + [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "4100332"]] + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str "Toyota,", Space, Str "Hiroko"]]]]] + (TableFoot ("",[],[]) []) +] |