【问题标题】:markdown table with long lines带有长线的降价表
【发布时间】:2013-04-11 17:29:32
【问题描述】:

我正在使用降价来创建表格。我的描述列包含很长的文本,因此当我换行时它在降价文件上看起来很糟糕:

Argument            | Description |
--------            | ----------- |
appDir              | The top level directory that contains your app. If this
option is used then it assumed your scripts are in |a subdirectory under this path. This option is not required. If it is not specified, then baseUrl below is the anchor point for finding things. If this option is specified, then all the files from the app directory will be copied to the dir: output area, and baseUrl will assume to be a relative path under this directory.  
baseUrl             | By default, all modules are located relative to this path. If baseUrl is not explicitly set, then all modules are loaded relative to the directory that holds the build file. If appDir is set, then baseUrl should be specified as relative to the appDir.
dir                 | The directory path to save the output. If not specified, then the path will default to be a directory called "build" as a sibling to the build file. All relative paths are relative to the build file. 
modules             | List the modules that will be optimized. All their immediate and deep dependencies will be included in the module's file when the build is done. If that module or any of its dependencies includes i18n bundles, only the root bundles will be included unless the locale: section is set above. 

我想换行,因为它对我来说更具可读性。
有没有办法让表格对编辑器更具可读性?

【问题讨论】:

  • FWIW:Mediawiki "markup" 具有更灵活的语法,允许每个表格行有多个文本行,但它的紧凑性稍差。
  • 这对于 Bitbucket 解析器是不可能的:我想对 readme.md 文件做同样的事情,但 Bitbucket 的文档明确指出:“您只能在表格中放置简单的行。” (source here)

标签: markdown octopress


【解决方案1】:

还有另一种选择。由于哲学认为 Markdown 应该是轻量级的,而不是标记语言,并且旨在供人类自然消费(与 SGML/HTML 样式格式相比),我相信在特殊情况下回退到 ASCII 艺术是很好和自然的.

对于这个特殊的任务,角色艺术是很自然的。因此,只需将您的表格缩进四个空格,并将其格式化以提高可读性,Markdown 会将其视为预先格式化的文本,双方就可以停止互相争斗。

例如:

|  Sequence   | Result                                                        |
|-------------|---------------------------------------------------------------|
| `a?c`       | Matches `abc`, `axc`, and `aac`. Does not match `ac`, `abbc`, | 
|             | or `a/c`.                                                     |
|-------------|---------------------------------------------------------------|
| `a*c`       | Matches "ac", "abc" and "azzzzzzzc". Does not match "a/c".    |
|-------------|---------------------------------------------------------------|
| `foo...bar` | Matches "foobar", "fooxbar", and "fooz/blaz/rebar". Does not  |
|             | match "fo/obar", "fobar" or "food/bark".                      |
|-------------|---------------------------------------------------------------|
| `....obj`   | Matches all files anywhere in the current hierarchy that end  |
|             | in ".obj". Note that the first three periods are interpreted  |
|             | as "...", and the fourth one is interpreted as a literal "."  |
|             | character.                                                    |
|-------------|---------------------------------------------------------------|

...完成了。

【讨论】:

  • 对快速阅读者的警告! 如果您需要获取 HTML table 即不要使用这个。这是生成一种 ASCII-art 表。在四个空格缩进的块(或 GFM 中的 ```-wrapped 块)之外使用它,您将获得每行单独的 tr(以及每条连字符行后单独的 tbody
  • 在移动设备或任何小屏幕/窗口上查看时会中断。
【解决方案2】:

我相信@Naor 是对的:您必须使用 HTML 来创建换行符,尽管答案中没有说明这一点。并且显示的完整表格代码并不是绝对必要的:要实现换行,您只需要双空格或<br /> 标记。 From the Markdown spec:

Markdown 支持“硬包装”文本段落。这不同 与大多数其他文本到 HTML 格式化程序(包括 Movable Type 的“转换换行符”选项) 将段落中的换行符转换为<br /> 标记。

当您确实想使用 Markdown 插入 <br /> 中断标记时,您结束 一行有两个或多个空格,然后输入 return。

请注意,我必须在文本中添加代码包装器,因为 SO 风格的 Markdown 需要转义 HTML 中断标记 - 所以我们知道 <br /> 有效。

但是,如果您想做一些更复杂的事情,比如我*,您可以使用 HTML 设置各种属性,如下所示:

<table width="300">
  <tr>
    <td> This is some text </td>
    <td> This is some somewhat longer block of text </td>
    <td> This is some very long block of text repeated to make it even longer. This is some very long block of text repeated to make it even longer. This is some very long block of text repeated to make it even longer.  </td>
  </tr>
</table>

我尝试将style="width:75%" 添加到&lt;td&gt;s,但没有任何影响。

*我应该注意到我遇到了这个问题,因为我在使用 GitHub 风格的 Markdown 编写表格中的代码时遇到了类似的问题,这非常痛苦。但我注意到这一点是因为它应该为我给出的示例着色:我所说的“有效”或“无效”的任何事情都来自那个环境。

编辑:如果您的表中有 code 块,可能会进一步值得注意的是,这无关紧要。不过,这不是 Markdown 的问题:HTML &lt;code&gt;&lt;/code&gt; 块会导致表格拉伸。

【讨论】:

    【解决方案3】:

    嗨,我也想知道同样的事情。我需要这个作为文档文件,这就是我处理这个的方式:

    | key | description                        |
    | --- | ---                                |
    | foo | bla bla blabla bla blabla bla bla  |
    |     | bla bla blabla bla bla bla bla bla |
    | bar | something else bla                 |
    

    我同意上述 Sam 的观点,即 Markdown 被认为是“硬包装”语言,因此这是作弊(我想这不是有效的 Markdown)。但例如在几个 Github 项目README.md 文件中,我看到人们像这样包装列表项:

     * foo
     * bla bla bla bla bla bla bla bla bla bla 
       bla bla bla bla bla bla bla bla bla
    

    我的学院还指出 http://www.tablesgenerator.com/markdown_tables 正在包装 表格类似的方式(感谢汤姆)

    因此,如果您正在做一些不会被解析的事情(例如 Github 文档),那么我认为可以使用我的示例,但如果您正在对 HTML 解析器或 Cucumber 测试表进行一些 Markdown,则不应该换行。

    但我可能错了

    【讨论】:

    • 此表变体将为第二个“bla bla”行生成一个单独的tr(至少,对于 Jekyll/gh-pages 和 dillinger.io)` td> bla bla blabla bla bla bla bla bla `
    • 我相信 Octopress 具有相同的解析行为
    【解决方案4】:

    遗憾的是,您必须为此使用 HTML

    <table>
    <tr>
    <th>Argument</th>
    <th>Description</th>
    </tr>
    <tr>
    <td>appDir</td>
    <td>The top level directory that contains your app. If this option is used then
    it assumed your scripts are in</td>
    </tr>
    <tr>
    <td>baseUrl</td>
    <td>By default, all modules are located relative to this path. If baseUrl is not
    explicitly set, then all modules are loaded relative to the directory that holds
    the build file. If appDir is set, then baseUrl should be specified as relative
    to the appDir.</td>
    </tr>
    <tr>
    <td>dir</td>
    <td>The directory path to save the output. If not specified, then the path will
    default to be a directory called "build" as a sibling to the build file. All
    relative paths are relative to the build file.</td>
    </tr>
    <tr>
    <td>modules</td>
    <td>List the modules that will be optimized. All their immediate and deep
    dependencies will be included in the module's file when the build is done. If
    that module or any of its dependencies includes i18n bundles, only the root
    bundles will be included unless the locale: section is set above.</td>
    </tr>
    </table>
    

    【讨论】:

    • 我尽量避免这种情况.. 使用 html 有什么意义.. 标记下一行的字符不是继续当前行吗?
    【解决方案5】:

    这不是一个捷径,而是一个格式化选项:

    而不是做:

    | TABLE  | NUMBER | RELATIONSHIPS |
    | ------ | ------ | ------------- |
    | TABLEA | NUM001 | TABLE2, TABLE4, TABLE7 |
    | TABLEB | NUM002 | TABLEA |
    

    你可以这样做:

    | TABLE  | NUMBER | RELATIONSHIPS |
    | ------ | ------ | ------------- |
    | TABLEA | NUM001 | TABLE2        | 
    |        |        | TABLE4        |
    |        |        | TABLE7        |
    | TABLEB | NUM002 | TABLEA        |
    

    只需在没有多行数据的列中留下空格即可。一个体面的代码编辑器可以帮助进行大量格式化,因此您无需手动输入多个空格。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-18
      • 2018-09-23
      • 1970-01-01
      • 1970-01-01
      • 2015-10-14
      • 1970-01-01
      • 2011-07-22
      • 1970-01-01
      相关资源
      最近更新 更多