在降价中创建分层表

Creating hierarchical tables in markdown

我想像这样构建一个复杂的 table:

| some thing | more important | up here |
|------------|----------------|---------|
| a  |a1     | b     |d       | c       |
|------------|----------------|---------|
| 1  |2      | 1     |2       |         |

是否可以使用 gf-markdown?

不,这对于 GFM 是不可能的,但是,对于原始 HTML.

是可能的

GitHub Flavored Markdown 的规范是 here。似乎不支持这样的 table 构造。值得注意的是,声明如下:

The header row must match the delimiter row in the number of cells. If not, a table will not be recognized...

The remainder of the table’s rows may vary in the number of cells. If there are a number of cells fewer than the number of cells in the header row, empty cells are inserted. If there are greater, the excess is ignored.

在这种情况下,您提供的 table 将被解释为:

| some thing | more important | up here |
|------------|----------------|---------|
| a          | a1             | b       |
| 1          | 2              | 1       |

也就是说,每行的最后两个单元格将被忽略。如果可能有助于记住:

Cells in one column don’t need to match length, though it’s easier to read if they are. Likewise, use of leading and trailing pipes may be inconsistent.

因此,仅仅因为您的 table 很容易被人类理解 reader,解析器就无法识别您的列对齐得很好。它只计算单元格的数量并忽略它们的实际排列。

顺便说一句,在转换您的 table 时(对于我上面的示例),我注意到您在 table 的每一行之间包含了一个“deliminator row”。 "deliminator row" 应该只在 header 行和第一个数据行之间。

这并不意味着不可能创建这样的 table。作为原始 Markdown syntax rules 状态:

For any markup that is not covered by Markdown’s syntax, you simply use HTML itself.

当然,出于安全原因,GFM disallows various raw HTML 标记。但是,tables 不在列表中。因此,您应该能够以您想要的任何结构创建原始 HTML table。

<table>
  <thead>
    <tr>
      <th colspan="2">some thing</th>
      <th colspan="2">more important</th>
      <th>up here</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>a</td>
      <td>a1</td>
      <td>b</td>
      <td>d</td>
      <td>c</td>
    </tr>
    <tr>
      <td>1</td>
      <td>2</td>
      <td>1</td>
      <td>2</td>
      <td></td>
    </tr>
  </tbody>
</table>

你可以看到一个例子 table in this gist (see the raw Markdown here)。我什至包含了您的 non-working 原始示例以供比较。