【问题标题】:How to write lists inside a markdown table?如何在降价表中编写列表?
【发布时间】:2013-11-25 20:51:53
【问题描述】:

可以在降价表中创建一个列表(项目符号,编号或不编号)。

表格如下所示:

| Tables        | Are           | Cool  |
| ------------- |:-------------:| -----:|
| col 3 is      | right-aligned | $1600 |
| col 2 is      | centered      |   $12 |
| zebra stripes | are neat      |    $1 |

列表如下所示:

* one
* two
* three

我可以以某种方式合并它们吗?

【问题讨论】:

    标签: html markdown github-flavored-markdown


    【解决方案1】:

    我不知道,因为我知道的所有降价参考,like this one,提及:

    单元格内容只能在一行

    您可以使用 Markdown Tables Generator 进行尝试(其示例看起来像您在问题中提到的那个,所以您可能已经知道了)。

    潘多克

    如果您使用的是Pandoc’s markdown(它扩展John Gruber’s markdown syntaxGitHub Flavored Markdown 所基于),您可以使用grid_tables

    +---------------+---------------+--------------------+
    | Fruit         | Price         | Advantages         |
    +===============+===============+====================+
    | Bananas       | $1.34         | - built-in wrapper |
    |               |               | - bright color     |
    +---------------+---------------+--------------------+
    | Oranges       | $2.10         | - cures scurvy     |
    |               |               | - tasty            |
    +---------------+---------------+--------------------+
    

    multiline_tables

    -------------------------------------------------------------
     Centered   Default           Right Left
      Header    Aligned         Aligned Aligned
    ----------- ------- --------------- -------------------------
       First    row                12.0 Example of a row that
                                        spans multiple lines.
    
      Second    row                 5.0 Here's another one. Note
                                        the blank line between
                                        rows.
    -------------------------------------------------------------
    

    【讨论】:

    • Markdown 表生成器是错误的,因为它接受新行,正如您所引用的那样,它不被接受。但感谢您提供宝贵的信息。
    • @GabrielPetrovay Markdown Tables Generator 是一项相对较新的服务,我并不感到惊讶;)但是关于“GitHub Flavored Markdown”,我的回答是正确的。
    • 我倾向于接受你的回答。但是我又等了 1-2 天,也许有人发布了一个 hack(如果答案被接受,没有人会看它,除非其他人有同样的问题)
    • @GabrielPetrovay 我同意。您还可以联系 GitHub 支持,看看他们对此有何评论。 (然后更新我的答案或发布您自己的答案)
    • @イオニカビザウ 我显然没有提到 HTML。使用 HTML,您可以重新创建任何降价功能,因此它不是有效的解决方案。问题是关于降价,不是 HTML。
    【解决方案2】:

    是的,您可以使用 HTML 合并它们。当我在 Github 的 .md 文件中创建表格时,我总是喜欢使用 HTML 代码而不是 markdown。

    Github Flavored Markdown 支持.md 文件中的基本 HTML。所以这就是答案:

    Markdown 与 HTML 混合:

    | Tables        | Are           | Cool  |
    | ------------- |:-------------:| -----:|
    | col 3 is      | right-aligned | $1600 |
    | col 2 is      | centered      |   $12 |
    | zebra stripes | are neat      |    $1 |
    | <ul><li>item1</li><li>item2</li></ul>| See the list | from the first column|
    

    或纯 HTML:

    <table>
      <tbody>
        <tr>
          <th>Tables</th>
          <th align="center">Are</th>
          <th align="right">Cool</th>
        </tr>
        <tr>
          <td>col 3 is</td>
          <td align="center">right-aligned</td>
          <td align="right">$1600</td>
        </tr>
        <tr>
          <td>col 2 is</td>
          <td align="center">centered</td>
          <td align="right">$12</td>
        </tr>
        <tr>
          <td>zebra stripes</td>
          <td align="center">are neat</td>
          <td align="right">$1</td>
        </tr>
        <tr>
          <td>
            <ul>
              <li>item1</li>
              <li>item2</li>
            </ul>
          </td>
          <td align="center">See the list</td>
          <td align="right">from the first column</td>
        </tr>
      </tbody>
    </table>
    

    这是它在 Github 上的样子:

    【讨论】:

    • 这很好,但是还有什么方法可以设置列表的样式吗?删除项目符号、边距等?例如,Github 似乎不接受ul 元素上的style="list-style: none" 标签。
    • @TreborRude 不,因为 Markdown 实际上不是 HTML。但是如果你使用一个库(例如marked),你可能有这个功能(将HTML与markdown结合起来)。
    • 没关系,我发现嵌入了&lt;br/&gt; 标记的&lt;span&gt; 标记完全符合我对样式列表所做的尝试。
    • @TreborRude 当然,您仍然可以有多个行单元格。可能它也接受&lt;p&gt; 标签。
    • 我很高兴地确认第一个(嵌入的 &lt;ul&gt;&lt;li&gt;foo&lt;/li&gt;&lt;/ul&gt;)也适用于 Bitbucket 服务器。
    【解决方案3】:

    如果您想要一个无项目符号列表(或任何其他非标准用法)或单元格中的更多行,请使用 &lt;br /&gt;

    | Event         | Platform      | Description |
    | ------------- |-----------| -----:|
    | `message_received`| `facebook-messenger`<br/>`skype`|
    

    【讨论】:

    • 可能是因为三年前这是唯一合理的答案?我同意你的观点,今天这是一个更好的答案。
    • 这是对Newline in markdown table? 的回答,而不是关于列表的问题
    • @Bergi 我赞成你的建议。 ;) 谷歌搜索让我想到了这个问题,这是我需要的解决方案。我认为这是可以忍受的(例如非项目符号列表),所以我把它放在这个地方。
    • 您可以添加带有 HTML 实体的项目符号:• facebook-messenger
      skype
    • markdown lint 将此标记为 no inline html
    【解决方案4】:

    我最近实施的另一种方法是将div-table pluginpanflute 结合使用。

    这会从一组隔离的 div 中创建一个表格(markdown 的 pandoc 实现中的标准),其布局与 html 类似:

    ---
    panflute-filters: [div-table]
    panflute-path: 'panflute/docs/source'
    ---
    
    ::::: {.divtable}
    :::: {.tcaption}
    a caption here (optional), only the first paragraph is used.
    ::::
    :::: {.thead}
    [Header 1]{width=0.4 align=center}
    [Header 2]{width=0.6 align=default}
    ::::
    :::: {.trow}
    ::: {.tcell}
    
    1. any
    2. normal markdown
    3. can go in a cell
    
    :::
    ::: {.tcell}
    ![](https://pixabay.com/get/e832b60e2cf7043ed1584d05fb0938c9bd22ffd41cb2144894f9c57aae/bird-1771435_1280.png?attachment){width=50%}
    
    some text
    :::
    ::::
    :::: {.trow bypara=true}
    If bypara=true
    
    Then each paragraph will be treated as a separate column
    ::::
    any text outside a div will be ignored
    :::::
    

    看起来像:

    【讨论】:

      【解决方案5】:

      如果你使用html方式:

      不要添加空行

      像这样:

      <table>
          <tbody>
      
              <tr>
                  <td>1</td>
                  <td>2</td>
              </tr>
      
              <tr>
                  <td>1</td>
                  <td>2</td>
              </tr>
      
          </tbody>
      </table>
      

      标记会中断。

      删除空行:

      <table>
          <tbody>
              <tr>
                  <td>1</td>
                  <td>2</td>
              </tr>
              <tr>
                  <td>1</td>
                  <td>2</td>
              </tr>
          </tbody>
      </table>
      

      【讨论】:

      • HTML 将忽略空行和多个空格,所以我看不出有任何问题。你能解释一下这里会发生什么吗?
      【解决方案6】:

      另一种解决方案,您可以在表格中添加&lt;br&gt; 标签

          |Method name| Behavior |
          |--|--|
          | OnAwakeLogicController(); | Its called when MainLogicController is loaded into the memory , its also hold the following actions :- <br> 1. Checking Audio Settings <br>2. Initializing Level Controller|
      

      【讨论】:

        【解决方案7】:

        如果您碰巧使用的是 Kramdown(Jekyll 的默认 Markdown 渲染器),那么您必须使用 nomarkdown extension {::nomarkdown}...{:/}

        例如:

        | Tables        | Are           | Cool  |
        | ------------- |:-------------:| -----:|
        | col 3 is      | right-aligned | $1600 |
        | col 2 is      | centered      |   $12 |
        | {::nomarkdown}<ul><li>one</li><li>two</li><li>three</li></ul>{:/} | Kramdown | bullets |
        

        【讨论】:

          猜你喜欢
          • 2016-10-22
          • 1970-01-01
          • 2020-11-07
          • 1970-01-01
          • 2015-01-06
          • 1970-01-01
          • 1970-01-01
          • 2014-02-14
          • 1970-01-01
          相关资源
          最近更新 更多