mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Fix HTML export of table with gutter (#5920)
This commit is contained in:
parent
d199546f9f
commit
240f238eee
@ -1526,11 +1526,7 @@ impl<'a> CellGrid<'a> {
|
|||||||
self.entry(x, y).map(|entry| match entry {
|
self.entry(x, y).map(|entry| match entry {
|
||||||
Entry::Cell(_) => Axes::new(x, y),
|
Entry::Cell(_) => Axes::new(x, y),
|
||||||
Entry::Merged { parent } => {
|
Entry::Merged { parent } => {
|
||||||
let c = if self.has_gutter {
|
let c = self.non_gutter_column_count();
|
||||||
1 + self.cols.len() / 2
|
|
||||||
} else {
|
|
||||||
self.cols.len()
|
|
||||||
};
|
|
||||||
let factor = if self.has_gutter { 2 } else { 1 };
|
let factor = if self.has_gutter { 2 } else { 1 };
|
||||||
Axes::new(factor * (*parent % c), factor * (*parent / c))
|
Axes::new(factor * (*parent % c), factor * (*parent / c))
|
||||||
}
|
}
|
||||||
@ -1602,6 +1598,21 @@ impl<'a> CellGrid<'a> {
|
|||||||
cell.rowspan.get()
|
cell.rowspan.get()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn non_gutter_column_count(&self) -> usize {
|
||||||
|
if self.has_gutter {
|
||||||
|
// Calculation: With gutters, we have
|
||||||
|
// 'cols = 2 * (non-gutter cols) - 1', since there is a gutter
|
||||||
|
// column between each regular column. Therefore,
|
||||||
|
// 'floor(cols / 2)' will be equal to
|
||||||
|
// 'floor(non-gutter cols - 1/2) = non-gutter-cols - 1',
|
||||||
|
// so 'non-gutter cols = 1 + floor(cols / 2)'.
|
||||||
|
1 + self.cols.len() / 2
|
||||||
|
} else {
|
||||||
|
self.cols.len()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given a cell's requested x and y, the vector with the resolved cell
|
/// Given a cell's requested x and y, the vector with the resolved cell
|
||||||
|
@ -282,7 +282,7 @@ fn show_cell_html(tag: HtmlTag, cell: &Cell, styles: StyleChain) -> Content {
|
|||||||
|
|
||||||
fn show_cellgrid_html(grid: CellGrid, styles: StyleChain) -> Content {
|
fn show_cellgrid_html(grid: CellGrid, styles: StyleChain) -> Content {
|
||||||
let elem = |tag, body| HtmlElem::new(tag).with_body(Some(body)).pack();
|
let elem = |tag, body| HtmlElem::new(tag).with_body(Some(body)).pack();
|
||||||
let mut rows: Vec<_> = grid.entries.chunks(grid.cols.len()).collect();
|
let mut rows: Vec<_> = grid.entries.chunks(grid.non_gutter_column_count()).collect();
|
||||||
|
|
||||||
let tr = |tag, row: &[Entry]| {
|
let tr = |tag, row: &[Entry]| {
|
||||||
let row = row
|
let row = row
|
||||||
|
26
tests/ref/html/col-gutter-table.html
Normal file
26
tests/ref/html/col-gutter-table.html
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>a</td>
|
||||||
|
<td>b</td>
|
||||||
|
<td>c</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>d</td>
|
||||||
|
<td>e</td>
|
||||||
|
<td>f</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>g</td>
|
||||||
|
<td>h</td>
|
||||||
|
<td>i</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
26
tests/ref/html/col-row-gutter-table.html
Normal file
26
tests/ref/html/col-row-gutter-table.html
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>a</td>
|
||||||
|
<td>b</td>
|
||||||
|
<td>c</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>d</td>
|
||||||
|
<td>e</td>
|
||||||
|
<td>f</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>g</td>
|
||||||
|
<td>h</td>
|
||||||
|
<td>i</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
26
tests/ref/html/row-gutter-table.html
Normal file
26
tests/ref/html/row-gutter-table.html
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>a</td>
|
||||||
|
<td>b</td>
|
||||||
|
<td>c</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>d</td>
|
||||||
|
<td>e</td>
|
||||||
|
<td>f</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>g</td>
|
||||||
|
<td>h</td>
|
||||||
|
<td>i</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -30,3 +30,30 @@
|
|||||||
[row],
|
[row],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
--- col-gutter-table html ---
|
||||||
|
#table(
|
||||||
|
columns: 3,
|
||||||
|
column-gutter: 3pt,
|
||||||
|
[a], [b], [c],
|
||||||
|
[d], [e], [f],
|
||||||
|
[g], [h], [i]
|
||||||
|
)
|
||||||
|
|
||||||
|
--- row-gutter-table html ---
|
||||||
|
#table(
|
||||||
|
columns: 3,
|
||||||
|
row-gutter: 3pt,
|
||||||
|
[a], [b], [c],
|
||||||
|
[d], [e], [f],
|
||||||
|
[g], [h], [i]
|
||||||
|
)
|
||||||
|
|
||||||
|
--- col-row-gutter-table html ---
|
||||||
|
#table(
|
||||||
|
columns: 3,
|
||||||
|
gutter: 3pt,
|
||||||
|
[a], [b], [c],
|
||||||
|
[d], [e], [f],
|
||||||
|
[g], [h], [i]
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user