Create table without header in markdown

2019-03-08 12:13发布

问题:

Is it possible to create a table without a header in markdown?

The HTML would look like this:

<table>
<tr>
    <td>Key 1</td>
    <td>Value 1</td>
</tr>
<tr>
    <td>Key 2</td>
    <td>Value 2</td>
</tr>
</table>

回答1:

Most markdown parsers don't support tables without headers. That means the separation line for headers is mandatory.

Parsers that do not support tables without headers

  • multimarkdown
  • Maruku: A popular implementation in ruby
  • byword: "All tables must begin with one or more rows of headers"
  • PHP Markdown Extra "second line contains a mandatory separator line between the headers and the content"

  • RDiscount Uses PHP Markdown Extra syntax.

  • Github Flavoured Markdown
  • Parsedown: A parser in PHP (used e.g. in Laravel emails)

Parsers that do support tables without headers.

  • Kramdown: A parser in Ruby
  • Text::MultiMarkdown: Perl CPAN module.
  • MultiMarkdown: Windows application.
  • ParseDown Extra: A parser in PHP.
  • Pandoc: A document converter for the command line written in Haskell (supports header-less tables via its simple_tables and multiline_tables extensions)

CSS solution

If you're able to change the CSS of the HTML output you can however leverage the :empty pseudo class to hide an empty header and make it look like there is no header at all.



回答2:

If you don't mind wasting a line by leaving it empty, consider the following hack. (it is a hack, and use this only if you don't like adding any additional plugins)

| | | |
|-|-|-|
|__Bold Key__| Value1 |
| Normal Key | Value2 |

To view how the above one could look, copy the above and visit https://stackedit.io/editor

It worked with gitlab/github's markdown implementations.



回答3:

I got this working with bitbucket's markdown by using a empty link

[]()  | 
------|------
Row 1 | row 2


回答4:

Omitting the header above the divider produces a headerless table in at least Perl Text::MultiMarkdown and in FletcherPenney MultiMarkdown

|-------------|--------|
|**Name:**    |John Doe|
|**Position:**|CEO     |

See PHP Markdown feature request


Empty headers in PHP Parsedown produce tables with empty headers that are usually invisible (depending on your CSS) and so look like headerless tables.

|     |     |
|-----|-----|
|Foo  |37   |
|Bar  |101  |


回答5:

This works well for me in GitHub. The first row is no longer bolded as it is not a header:

<table align="center">
    <tr>
        <td align="center"><img src="docs/img1.png?raw=true" alt="some text"></td>
        <td align="center">Some other text</td>
        <td align="center">More text</td>
    </tr>
    <tr>
        <td align="center"><img src="docs/img2.png?raw=true" alt="some text"></td>
        <td align="center">Some other text 2</td>
        <td align="center">More text 2</td>
    </tr>
</table>

Check an sample HTML table without header here.



回答6:

$ cat foo.md
Key 1 | Value 1
Key 2 | Value 2
$ kramdown foo.md
<table>
  <tbody>
    <tr>
      <td>Key 1</td>
      <td>Value 1</td>
    </tr>
    <tr>
      <td>Key 2</td>
      <td>Value 2</td>
    </tr>
  </tbody>
</table>


回答7:

At least for the Github Flavoured Markdown, you can give the illusion by simply making all the non-header row entries as bold:

|Regular | text | in header | turns bold |
|-|-|-|-|
| __So__ | __bold__ | __all__ | __table entries__ |
| __and__ | __it looks__ | __like a__ | __"headerless table"__ |


回答8:

Many of the suggestions unfortunately do not work for all markdown viewers/editors, for instance, in my case - the popular Markdown Viewer Chrome extension but do work with iA Writer.

What does seem to work across both of these popular programs (and might work for your particular application) is to use html comment blocks ('<!-- -->'):

| <!-- -->    | <!-- -->    |
|-------------|-------------|
| Foo         | Bar         |

Like some of the earlier suggestions stated, this does add an empty header row in your markdown viewer/editor and is inevitable. In iA Writer, its aesthetically small enough that it doesn't get in my way too much.



回答9:

Have you tried the Senseful Solutions format text as a table tool?

I think you still need headers but it makes creating tables a lot easier for SO.



回答10:

@thamme-gowda's solution works for images too!

| | |:----------------------------------------------------------------------------:| | ![](https://gravatar.com/avatar/4cc702785290b4934c531c56f6061e5e "Tonejito") |

You can check this out on a gist I made for that. Here is a render of the table hack on GitHub and GitLab:



回答11:

I use <span> in the 1st colume header

 <span> |  
  ---   |   ---     
Value   |  Value  
Value   |  Value

it creates an empty header with border, but with 1/2 size