我可以在降价中合并 table 行吗

Can I merge table rows in markdown

有没有办法在 ReadMe.md 等降价文件中的 table 列中创建合并行?

像这样:

不,GitHub-Flavored Markdown 无法做到这一点。正如 spec 解释的那样(强调):

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:

当然,您始终可以退回到原始 HTML。事实上,GitHub 在其 whitelist.

中包含 rowspan(和 colspan)属性
<table>
    <thead>
        <tr>
            <th>Layer 1</th>
            <th>Layer 2</th>
            <th>Layer 3</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td rowspan=4>L1 Name</td>
            <td rowspan=2>L2 Name A</td>
            <td>L3 Name A</td>
        </tr>
        <tr>
            <td>L3 Name B</td>
        </tr>
        <tr>
            <td rowspan=2>L2 Name B</td>
            <td>L3 Name C</td>
        </tr>
        <tr>
            <td>L3 Name D</td>
        </tr>
    </tbody>
</table>

https://jsfiddle.net/7h89y55r/

亲自尝试

标准通用标记不支持 table 并且不引用或推荐任何特定的 table 扩展 (latest revision permalink as of 2018-03)。您的问题并未具体询问 Github-flavored Markdown (GFM),但 GFM 基于不支持此 table 扩展名的通用标记。

MultiMarkdown from at least v5 supports these types of tables (docs permalink) 与 PHP Markdown Extra 的 Michael Fortin 相同,转向:

|             |          Grouping           ||
First Header  | Second Header | Third Header |
 ------------ | :-----------: | -----------: |
Content       |          *Long Cell*        ||
Content       |   **Cell**    |         Cell |

New section   |     More      |         Data |
And more      | With an escaped '\|'         ||  
[Prototype table]

进入

我通常将 markdown-it (VSCode built-in markdown & my Ghost blog use it) which only supports Github-flavored tables, but someone created an extension (markdown-it-multimd-table) 与这些 table 一起使用。最终,您有多种选择。

vscode 插件 Markdown Extended supports extended table formats described by other answers by integrating markdown-it-multimd-table

我在关于替代解决方案的评论中回答了 OP 的问题,但评论被压缩到一行。将其添加为此处的答案以正确显示格式。

您可以使用 AsciiDoc 而不是 Markdown。 GitHub 现在支持了。只需使用 README.adoc 而不是 README.md 您在 AsciiDoc 语法中的 table:

[cols="^.^,^.^,^.^"]
|===
|Layer1 |Layer2 |Layer3

.4+|L1 Name .2+|L2 Name A |L3 Name A
|L3 Name B
.2+|L2 Name B |L3 Name C
|L3 Name D
|===

如果你使用的是 Jekyll,支持 table 单元 alignmentmerging 等等,我想下面我写的可以帮助你更轻松地做到这一点。

jekyll-spaceship - A Jekyll plugin to provide powerful supports for table, mathjax, plantuml, mermaid, video, youtube, emoji, vimeo, dailymotion, etc.

https://github.com/jeffreytse/jekyll-spaceship

For now, these extended features are provided:

  • Cells spanning multiple columns
  • Cells spanning multiple rows
  • Cells text align separately
  • Table header not required
  • Grouped table header rows or data rows

降价:

上面的代码将被解析为:

在标准 Markdown 中是不可能的,但是,有一些解决方案支持此功能。前面提到的Multimarkdown之一,但我想推荐另一个支持它的在线Markdown编辑器:μr² editor

它支持行和列合并,还可以从输出中生成漂亮的 PDF。示例:

|               |          Grouping             ||         Grouping 2         ||  Not Grouped    |
| First Header  | Second Header | Third Header   | Forth Header | Fifth Header | Sixth Header    |
| ------------- | :-----------: | -------------: | :----------: | :----------: | --------------- |
| Tall Cell     |          *Long Cell*          ||         *Long Long Cell*                    |||
| ^^            |   **Bold**    | 1. first item  | *Italic*     | 3. third item | + first point  |\
| ^^            |               | 1. second item |              | 1. forth item | + second point |

| New section   |     More      |         Data   | ... - -- --- |||
| And more      | With an escaped \|          || "Try 'quotes' in quotes "         |||
[Compicated table]

将呈现为:

我正在使用 Postman 记录一个 API,发现你可以通过在你的 | 中插入 HTML 来混合行自述文件 .md 符号和 HTML。 |分离器,使设计更加稳健。我假设其他使用标记的平台(例如 GitHub)也是一样的,试试看它是否适合您。

以下示例将 table 嵌套在 table 单元格中:

       | Field  | Description |  Optional | Default |
       | ------ | ----------- | --------- | ------- |
       | manual_entry_indicator | no: is not is allow manual entry <br /> yes: is manual entry enabled| yes | no |
       | amounts | json object containing all transaction amounts <br /> <br /> <table> <tr> <td> Subfield </td> <td> Description </td> <td> Optional </td> <td> Default </td> </tr> <tr> <td> tip </td>  <td> transaction tip amount </td> <td> yes </td> <td> NA </td> </tr> <tr> <td> total </td> <td> equal to Base  Amount + Base amount for  Reduced State Tax + City Tax + State Tax + Reduced State Tax + Tip or Cash back </td> <td> no </td> <td> NA </td> </tr> <tr> <td> cashback </td> <td> cash back amount </td> <td> yes </td> <td> NA </td> </tr> <tr> <td> state_tax </td> <td> State tax amount </td> <td> yes </td> <td> NA </td> </tr> <tr> <td> city_tax </td> <td> City tax amount </td> <td> yes </td> <td> NA </td> </tr> <tr> <td> reduced_tax </td> <td> Reduced state tax amount </td> <td> yes </td> <td> NA </td> </tr> <tr> <td> base_reduced_tax </td> <td> Reduced state tax base amount </td> <td> yes </td> <td> NA </td> </tr> </table> | no | NA |