Create a table without a header in Markdown

后端 未结 11 2026
有刺的猬
有刺的猬 2021-01-30 07:42

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

The HTML would look like this:



        
                      
相关标签:
11条回答
  • 2021-01-30 08:27
    $ 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>
    
    0 讨论(0)
  • 2021-01-30 08:30

    The following 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 a sample HTML table without a header here.

    0 讨论(0)
  • 2021-01-30 08:31

    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)
    • Flexmark: A parser in Java.

    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.

    0 讨论(0)
  • 2021-01-30 08:33

    At least for the GitHub Flavoured Markdown, you can give the illusion by making all the non‑header row entries bold with the regular __ or ** formatting:

    |Regular | text | in header | turns bold |
    |-|-|-|-|
    | __So__ | __bold__ | __all__ | __table entries__ |
    | __and__ | __it looks__ | __like a__ | __"headerless table"__ |
    
    0 讨论(0)
  • 2021-01-30 08:33

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

    0 讨论(0)
提交回复
热议问题