长行markdown表格

问题描述 投票:0回答:6

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

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. 

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

markdown word-wrap octopress
6个回答
11
投票

还有另一种选择。由于其理念是 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.                                                    |
|-------------|---------------------------------------------------------------|

...完成了。


6
投票

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

<br />
标记。 来自 Markdown 规范

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%"
添加到
<td>
中,但没有影响。

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

编辑:可能还值得注意的是,如果您的表中有

code
块,则这无关紧要。但这对于 Markdown 来说不是问题:HTML
<code></code>
块会导致表格拉伸。


6
投票

遗憾的是您必须使用 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>

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 操作,则不应换行。

但我可能错了


2
投票

如果您希望它仅用于预览或 html 导出,请在您想要换行的位置添加

<br>

| table | column         |
| ---   | ---            |
| row1  | line1<br>line2 |
| row2  | other          |

-1
投票

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

而不是这样做:

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

你可以这样做:

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

只需在没有多行数据的列中保留空格即可。一款像样的代码编辑器可以帮助完成许多格式设置,因此您无需手动输入多个空格。

© www.soinside.com 2019 - 2024. All rights reserved.