Skip to content

Commit a0795b1

Browse files
authored
Bugfix/issue 4073 (#4088)
* support more html content where a table is present * fix falsy check
1 parent 7ea8701 commit a0795b1

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

src/resources/filters/common/tables.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ local tableCheckers = {
174174
function hasTable(raw)
175175
for i, checker in ipairs(tableCheckers) do
176176
local val = checker(raw)
177-
if val ~= nil then
177+
if val then
178178
return true
179179
end
180180
end

src/resources/filters/normalize/parsehtml.lua

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,16 @@ function parse_html_tables()
99
if _quarto.format.isRawHtml(el) then
1010
-- if we have a raw html table in a format that doesn't handle raw_html
1111
-- then have pandoc parse the table into a proper AST table block
12-
local tableBegin,tableBody,tableEnd = el.text:match(htmlTablePattern())
12+
local pat = htmlTablePattern()
13+
local i, j = string.find(el.text, pat)
14+
if i == nil then
15+
return nil
16+
end
17+
18+
local tableBegin,tableBody,tableEnd = el.text:match(pat)
1319
if tableBegin then
20+
local before_table = string.sub(el.text, 1, i - 1)
21+
local after_table = string.sub(el.text, j + 1)
1422
local tableHtml = tableBegin .. "\n" .. tableBody .. "\n" .. tableEnd
1523
local tableDoc = pandoc.read(tableHtml, "html")
1624
local skip = false
@@ -24,7 +32,15 @@ function parse_html_tables()
2432
if skip then
2533
return nil
2634
end
27-
return tableDoc.blocks
35+
local blocks = pandoc.Blocks({})
36+
if before_table ~= "" then
37+
blocks:insert(pandoc.RawBlock(el.format, before_table))
38+
end
39+
blocks:extend(tableDoc.blocks)
40+
if after_table ~= "" then
41+
blocks:insert(pandoc.RawBlock(el.format, after_table))
42+
end
43+
return blocks
2844
end
2945
end
3046
return el
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: issue-4073
3+
_quarto:
4+
tests:
5+
html:
6+
ensureHtmlElements:
7+
- ["div.cell-output style"]
8+
- []
9+
---
10+
11+
```{python}
12+
import pandas as pd
13+
14+
df = pd.DataFrame({'text': ['foo', 'bar'],'number': [1, 2]})
15+
16+
df.style.set_properties(subset=["number"], **{'text-align': 'right'})
17+
```
18+
</style>

0 commit comments

Comments
 (0)