Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I merge table rows in markdown

Is there a way to create merged rows in a column of table in markdown files like ReadMe.md files?

Something like this:

table

like image 951
dev-masih Avatar asked Sep 26 '22 03:09

dev-masih


People also ask

Can you do tables in Markdown?

Markdown makes it simple to format text online, such as bold text, and links. You can even make tables with Markdown.

How do I break a line in a table in Markdown?

A newline in Markdown is created by “2 spaces at the end of the line and a single newline”. where the _ are spaces.

How do I edit a table in Markdown?

Enter the table data into the table: select and copy (Ctrl+C) a table from the spreadsheet (e.g. Google Docs, LibreOffice Calc, webpage) and paste it into our editor -- click a cell and press Ctrl+V. or just double click any cell to start editing it's contents -- Tab and Arrow keys can be used to navigate table cells.

How do I merge table cells in HTML?

Highlight two or more cells in your table. Right-click the highlighted cells. Click Table and then select Merge Cells.


2 Answers

No, this is not possible with GitHub-Flavored Markdown. As the spec explains (emphasis added):

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:

Of course, you can always fall back to raw HTML. In fact, GitHub includes the rowspan (and colspan) attribute on their whitelist.

<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>

Try it yourself at https://jsfiddle.net/7h89y55r/

like image 116
Waylan Avatar answered Oct 12 '22 04:10

Waylan


The standard commonmark does not support tables and does not refer to or recommend any specific table extensions (latest revision permalink as of 2018-03). Your question doesn't specifically ask about Github-flavored Markdown (GFM), but GFM is based on commonmark with a table extension which doesn't support this.

MultiMarkdown from at least v5 supports these types of tables (docs permalink) in the same way that Michael Fortin for PHP Markdown Extra does, turning:

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

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

into Table

I'm commonly using 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) for these tables with it. Ultimately, you've got options.

like image 34
Ben Creasy Avatar answered Oct 12 '22 03:10

Ben Creasy