Skip to content

Commit

Permalink
Merge pull request #10906 from quarto-dev/fix/table-style-new-pandoc
Browse files Browse the repository at this point in the history
Handle Pandoc change in table classes
  • Loading branch information
cscheid authored Sep 30, 2024
2 parents 921fdb0 + 477d1d2 commit b7d0ddd
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ _quarto:
html:
ensureHtmlElements:
-
- 'table'
- 'table.table'
- []
typst:
ensureTypstFileRegexMatches:
Expand Down
16 changes: 16 additions & 0 deletions src/resources/filters/quarto-post/html.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ function render_html_fixups()

return {
Table = function(tbl)
-- Add back classes 'odd', (or 'header' in table header) / 'even' to table rows
-- They were removed in pandoc 3.2.1 but are useful for styling pandoc processed tables
-- Quarto detects .odd class
local function add_odd_even (rows, odd)
odd = odd or 'odd'
for rownum, row in ipairs(rows) do
row.classes:insert((rownum % 2) == 0 and 'even' or odd)
end
return rows
end
add_odd_even(tbl.head.rows, 'header')
for _, tblbody in ipairs(tbl.bodies) do
add_odd_even(tblbody.body)
end
add_odd_even(tbl.foot.rows)

-- this requires bootstrap CSS
if quarto.doc.crossref.cap_location(tbl) == "top" then
tbl.classes:insert("caption-top")
Expand Down
3 changes: 2 additions & 1 deletion src/resources/formats/html/_quarto-rules.scss
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ tr.header > th > p:last-of-type {
margin-bottom: 0px;
}

table {
table,
table.table {
margin-top: 0.5rem;
margin-bottom: 0.5rem;
}
Expand Down
2 changes: 1 addition & 1 deletion src/resources/formats/revealjs/quarto.scss
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ $panel-sidebar-padding: 0.5em;

// https://github.com/quarto-dev/quarto-cli/issues/3380

div.cell-output-display div.pagedtable-wrapper table {
div.cell-output-display div.pagedtable-wrapper table.table {
font-size: 0.6em;
}

Expand Down
2 changes: 2 additions & 0 deletions tests/docs/playwright/html/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*_files/
*.html
32 changes: 32 additions & 0 deletions tests/docs/playwright/html/markdown-tables.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: Markdown Tables
---

They should be styled by Quarto

| Col1 | Col2 | Col3 |
|------|------|------|
| A | B | C |
| E | F | G |
| A | G | G |

: My Caption {#tbl-letters}

See @tbl-letters.

## Computational table

<!-- This is equivalent to intermediate markdown from a `knitr::kable()` output with `echo: false` -->

:::: cell
::: cell-output-display
| Sepal.Length | Sepal.Width | Petal.Length | Petal.Width | Species |
|-------------:|------------:|-------------:|------------:|:--------|
| 5.1 | 3.5 | 1.4 | 0.2 | setosa |
| 4.9 | 3.0 | 1.4 | 0.2 | setosa |
| 4.7 | 3.2 | 1.3 | 0.2 | setosa |
| 4.6 | 3.1 | 1.5 | 0.2 | setosa |
| 5.0 | 3.6 | 1.4 | 0.2 | setosa |
| 5.4 | 3.9 | 1.7 | 0.4 | setosa |
:::
::::
2 changes: 2 additions & 0 deletions tests/docs/playwright/ojs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.html
*_files
2 changes: 1 addition & 1 deletion tests/docs/smoke-all/2023/10/10/issue-7187-b.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ _quarto:
html:
ensureHtmlElements:
- []
- ["div[data-html-table-processing]"]
- ["table.table", "div[data-html-table-processing]"]
---

::: {html-table-processing="none"}
Expand Down
2 changes: 1 addition & 1 deletion tests/docs/smoke-all/2023/10/10/issue-7187.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ _quarto:
html:
ensureHtmlElements:
- []
- ["table[data-quarto-postprocess='true']"]
- ["table.table"]
---


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ _quarto:
html:
ensureHtmlElements:
-
- "figure.quarto-float-tbl div#tbl-cars figure.quarto-subfloat-tbl table"
- "figure.quarto-float-tbl div#tbl-cars figure.quarto-subfloat-tbl table.table"
- "figure.quarto-float-tbl div#tbl-cars figure.quarto-subfloat-tbl figcaption.quarto-subfloat-caption"
- "figure.quarto-float-tbl div#tbl-pressure figure.quarto-subfloat-tbl table"
- "figure.quarto-float-tbl div#tbl-pressure figure.quarto-subfloat-tbl table.table"
- "figure.quarto-float-tbl div#tbl-pressure figure.quarto-subfloat-tbl figcaption.quarto-subfloat-caption"
- "div#tbl-tables > figure.quarto-float-tbl > figcaption.quarto-float-caption"
- []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ title: Knitr Table Test
# revealjs:
# ensureHtmlElements:
# -
# - "figure.quarto-float-tbl div#tbl-cars figure.quarto-float-tbl table"
# - "figure.quarto-float-tbl div#tbl-cars figure.quarto-float-tbl table.table"
# - "figure.quarto-float-tbl div#tbl-cars figure.quarto-float-tbl figcaption.quarto-subfloat-caption"
# - "figure.quarto-float-tbl div#tbl-pressure figure.quarto-float-tbl table"
# - "figure.quarto-float-tbl div#tbl-pressure figure.quarto-float-tbl table.table"
# - "figure.quarto-float-tbl div#tbl-pressure figure.quarto-float-tbl figcaption.quarto-subfloat-caption"
# - "div#tbl-tables > figure.quarto-float-tbl > figcaption.quarto-float-caption"
# - []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ format: typst
# html:
# ensureHtmlElements:
# -
# - "figure.quarto-float-tbl div#tbl-cars figure.quarto-float-tbl table"
# - "figure.quarto-float-tbl div#tbl-cars figure.quarto-float-tbl table.table"
# - "figure.quarto-float-tbl div#tbl-cars figure.quarto-float-tbl figcaption.quarto-subfloat-caption"
# - "figure.quarto-float-tbl div#tbl-pressure figure.quarto-float-tbl table"
# - "figure.quarto-float-tbl div#tbl-pressure figure.quarto-float-tbl table.table"
# - "figure.quarto-float-tbl div#tbl-pressure figure.quarto-float-tbl figcaption.quarto-subfloat-caption"
# - "div#tbl-tables > figure.quarto-float-tbl > figcaption.quarto-float-caption"
# - []
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/playwright-tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Deno.test({
try {
// run playwright
const res = await execProcess({
cmd: [Deno.build.os == "windows" ? "npx.cmd" : "npx", "playwright", "test"],
cmd: [Deno.build.os == "windows" ? "npx.cmd" : "npx", "playwright", "test", "--ignore-snapshots"],
cwd: "integration/playwright",
});
if (!res.success) {
Expand Down
16 changes: 11 additions & 5 deletions tests/integration/playwright/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import { defineConfig, devices } from '@playwright/test';
*/
// require('dotenv').config();

const isCI = !!process.env.CI;

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
/* Look for test files in the "tests" directory, relative to this configuration file. */
testDir: "./tests",
snapshotPathTemplate: "{testDir}/__screenshots__/{testFilePath}/{platform}/{arg}{ext}",
/* Maximum time one test can run for. */
timeout: 30 * 1000,
expect: {
Expand All @@ -24,13 +27,16 @@ export default defineConfig({
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
forbidOnly: isCI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
retries: isCI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
workers: isCI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: [["html", { open: "never" }]],
reporter: [
["html", { open: "never" }],
isCI ? ['github'] : ['line'],
],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
Expand Down Expand Up @@ -91,7 +97,7 @@ export default defineConfig({
webServer: {
command: 'python -m http.server 8080',
url: 'http://127.0.0.1:8080',
reuseExistingServer: !process.env.CI,
reuseExistingServer: !isCI,
cwd: '../../docs/playwright',
},
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions tests/integration/playwright/tests/html-tables.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { test, expect } from '@playwright/test';

test('Markdown tables are styled correctly', async ({ page }) => {
await page.goto('html/markdown-tables.html');
await expect(page.getByRole('figure', { name: 'Table 1: My Caption' }).locator('table')).toHaveScreenshot()
await expect(page.locator('a.quarto-xref[href="#tbl-letters"]')).toContainText('Table 1');

await expect(page.locator('#computational-table table')).toHaveScreenshot()

});

0 comments on commit b7d0ddd

Please sign in to comment.