pandas DataFrame output keeps its `border="1"` and scoped `<style>`, and gets no Bootstrap table classes

未关闭
#1,408 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
57/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
bootstrap, pandas, python, rust
领域
backend, web-dev

调研方向

Start with bootstrapHtmlPostprocessor in src/format/html/format-html-bootstrap.ts and compare its handling of parsed tables with TableBootstrapClassTransform, which currently handles Markdown tables. Reproduce with the supplied pandas DataFrame example using html-table-processing: none, then inspect the raw HTML output. Done means the raw table receives the Bootstrap classes and loses the border, preceding scoped style, and row alignment style, matching the expected output.

由索引模型根据 Issue 内容生成。

描述

This issue was written by Claude while adding q2 support to
Great Docs. The output shown comes from running each repro.

Bug description

A pandas DataFrame's HTML output is a <table border="1" class="dataframe">. It comes after a
<style scoped> element that right-aligns the header, and its header row has
style="text-align: right;". Quarto 1 tidies this table in its Bootstrap HTML post-processor
(bootstrapHtmlPostprocessor in src/format/html/format-html-bootstrap.ts, around line 476):

  • it removes border, the rows' style and the <style> just before the table;
  • it adds table table-sm table-striped small.

It does the same for R's table.data-frame, adding only the classes. So a DataFrame looks like
any other table on the page.

q2 writes the table as pandas wrote it. The browser draws a 1px border round every cell, with no
cell padding, and right-aligns the header. That's the default look of an HTML table, not a
Bootstrap one. q2's TableBootstrapClassTransform gives Bootstrap classes only to Markdown tables
(Block::Table), and this table is raw HTML.

By default, Quarto 1 parses the table into a Markdown table first (html-table-processing), and
then adds the same classes to it. q2 has no HTML reader, so it can't. Sites that set
html-table-processing: none take the post-processor path above; Great Docs does, for Great
Tables output. q2 leaves the table raw either way.

Great Docs now does the post-processor's cleanup itself in q2 builds, in a post-render script.

Steps to reproduce
mkdir dataframe && cd dataframe
cat > page.qmd <<'QMD'
---
title: DataFrame output
html-table-processing: none
---

```{python}
import pandas as pd

pd.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]})
```
QMD
q2 render page.qmd
grep -B14 -A3 '<table' page.html
Actual behavior

With q2 0.47.0, and with the nightly 0.48.0-nightly.20261125:

<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>

Without html-table-processing: none, the table is the same: <table border="1" class="dataframe">.

Expected behavior

As in Quarto 1.9.37:

<div>

<table class="dataframe table table-sm table-striped small">
  <thead>
    <tr>
      <th></th>

Without html-table-processing: none, Quarto 1 writes <table class="dataframe caption-top table table-sm table-striped small" data-border="1">, from the parsed table.

主要语言
Rust
星标
316
派生
23
平均合并
11 小时 49 分钟
30 天内合并 PR
245

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

quarto-dev/q2 的其他 Issue

查看 quarto-dev/q2 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。