markdown - 在减价表中换行

标签 markdown

我的目标是编写易于阅读的文档文件,以纯文本格式和html格式显示。

问题在于使用 Markdown 表。例如,我的表带有长字符串:

| Name      | Description                                                                                                                  |
|-----------|------------------------------------------------------------------------------------------------------------------------------|
| some_name | Very very very long description for some_name property that should be easy to read even in plain text form even in html form |

这个markdown会生成普通的HTML,但是由于行很长,因此无法以纯文本格式读取它。

如果我写这样的话:
| Name      | Description                    |
|-----------|--------------------------------|
| some_name | Very very very long description|
|           | for some_name property that    |
|           | should be easy to read even in |
|           | plain text form even in html   |
|           | form                           |
|-----------|--------------------------------|

然后,它很容易阅读,但是会生成难看的html演示文稿。

有什么办法可以将减价表中的长行换行吗?

最佳答案

这取决于您使用的Markdown实现。

例如,Pandoc的multiline_tablesgrid_tables都支持多行单元格,但是,更流行的pipe_tables不支持。请注意,默认情况下这些功能均未启用,但必须通过选项明确启用,或作为Markdown变体的一部分启用。让我们依次看一下:

multiline_tables

这些表使用空白行分隔每一行。

------------------------------------------
Name       Description
---------- -------------------------------
some_name  Very very very long description
           for some_name property that
           should be easy to read even in
           plain text form even in html
           form  

other_name A second row
------------------------------------------

我知道(至少)multiline_tables有两个问题:
  • Pandoc仅支持它们。因此,如果您希望任何其他Markdown实现都处理Markdown,则不能使用它们。
  • 在单元格中编辑多行文本可能很麻烦,因为您需要在文本编辑器中手动将文本换行。

  • grib_tables

    这些本质上是Emacs table mode的克隆,也是restructuredtext's grid tables的更严格实现。
    +------------+--------------------------------+
    | Name       | Description                    |
    +============+================================+
    | some_name  | Very very very long description|
    |            | for some_name property that    |
    |            | should be easy to read even in |
    |            | plain text form even in html   |
    |            | form                           |
    +------------+--------------------------------+
    | other_name | A second row                   |
    +------------+--------------------------------+
    

    每行由-+字符的组合分隔。

    grid_tables的已知问题是:
  • 其他Markdown实现(我知道)不支持它。
  • 尽管它在emacs中获得了良好的编辑器支持,但您仍受emac困扰,这可能是好事,也可能不是好事。

  • pipe_tables

    除了Pandoc之外,它们还受到许多实现的支持,包括PHP Markdown ExtraMultiMarkdownGitHub Flavored MarkdownPython-Markdown *和Kramdown等。
    | Name       | Description                                                                                                                  |
    | ---------- | ---------------------------------------------------------------------------------------------------------------------------- |
    | some_name  | Very very very long description for some_name property that should be easy to read even in plain text form even in html form |
    | other_name | A second row                                                                                                                 |
    

    请注意,该语法没有提供任何方法来定义一行的结束时间和另一行的开始时间(与其他类型的表不同)。由于您无法定义行之间的分隔,因此它唯一可行的方法是每一行都是自己的行。因此,一行不能包含多行文本。

    最后,如Pandoc的文档所述:

    Since the pipes indicate column boundaries, columns need not be vertically aligned.



    在这种情况下,可以在文本编辑器中像这样更轻松地格式化表格:
    | Name       | Description  |
    | ---------- | ------------ |
    | some_name  | Very very very long description for some_name property that should be easy to read even in plain text form even in html form |
    | other_name | A second row |
    

    这肯定会有所帮助,并消除了手动换行的需要。长线不理想。但是,由于跨实现的广泛支持,对于大多数用户而言,它是最佳选择。

    MultiMarkdown的表格文档提供了一个有趣的发现(原始内容为重点):

    MultiMarkdown table support is designed to handle most tables for most people; it doesn’t cover all tables for all people. If you need complex tables you will need to create them by hand or with a tool specifically designed for your output format. At some point, however, you should consider whether a table is really the best approach if you find MultiMarkdown tables too limiting.



    *全面披露:我是Python-Markdown的维护者

    关于markdown - 在减价表中换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57165371/

    相关文章:

    markdown - 在 Markdown 中标记电子邮件签名或邮政地址

    html - 如何在 Markdown 表中编写项目符号列表?

    grails - Groovy和GSP中的Markdown超链接

    python - 如何在我的网站上将 WMD markdown 语法转换为 HTML?

    html - 用于渲染 html 子集的 Django templatetag

    python - 当我尝试注册 pypi 时,为什么 setup.py 失败?

    R Markdown 数学方程对齐

    python - 如何在 PyCharm 中使用 python 的 markdown?

    image - 在 Markdown 中包含图像时如何转义文件名中的空格?

    documentation - 比较和对比轻量级标记语言