如何强制换行?

How to force a linebreak?

我注意到,如果我在图像后立即开始一个新段落,大多数渲染器会在图像和下面的文本之间留下不充分的 space。该段最终看起来像一个传奇。虽然这在我确实想要图例时很有用,但有时我只是想在两段之间插入一张图片,并在下方充分 spaced 和上面一样。

我目前更正了这个问题:

Lorem ipsum dolor sit amet, consectetur adipiscing elit:

[IMAGE]

<br/><br/>

Pellentesque pharetra turpis vitae velit consequat placerat. Duis sed volutpat neque, et scelerisque orci.

但这让我觉得不够优雅:我想尽可能避免 HTML。

还有其他方法可以强制换行吗?

我正在使用 Markdown Preview Plus for Atom 进行渲染。

tl;博士

简而言之,您不能使用纯 Markdown。您需要使用原始 HTML and/or CSS 样式。最简单的是将 <br/><br/> 插入到您的文档中。

详细解释

浏览器通过从样式 sheet 获取指令来确定如何在页面中显示各种 HTML 元素。那些样式sheets可以从多个来源获得:(1)浏览器默认样式sheets,(2)本地user-defined样式sheets,(3)样式sheet 由文档作者提供,以及 (4) 嵌入在 HTML 中的内联样式(this 引人入胜,尽管冗长,文章分解了整个过程)。

我们要考虑的是第一个;浏览器的默认样式 sheets。这些告诉浏览器各种元素的默认样式、段落的填充、不同级别的大小 headers、列表项的缩进和项目符号等。事实上,快速 search出现一大堆 so-called "reset" 样式 sheet 可以撤消所有这些默认样式。

这就是您遇到的情况,默认样式没有在图像和其后的段落之间提供足够的填充。您有几个选项可以解决这个问题:

  1. 定义一个用户样式 sheet(存储在您的本地计算机上),您的浏览器将使用它来 alter/override 默认样式 sheet。当然,这只会影响你在那台机器上。任何其他机器仍将使用默认样式。

  2. 为您的页面定义样式 sheet,通过模板或其他方式附加到页面。但是,如果您在不允许此类控制的主机(如 wiki)上发布文档,那么这也无济于事。

  3. 在文档中定义一些内联样式。当然,这意味着您需要为图像定义原始 HTML。在某些服务上,原始 HTML and/or 内联 CSS 可能会被删除。

最终这完全取决于您打算如何使用您的文档。但这并不能真正回答你的问题。你怎么能在 Markdown 中完成这个?简而言之,你不能。

作为 Markdown 的作者explains(重点保留):

Markdown's syntax is intended for one purpose: to be used as a format for writing for the web.

Markdown is not a replacement for HTML, or even close to it. Its syntax is very small, corresponding only to a very small subset of HTML tags. The idea is not to create a syntax that makes it easier to insert HTML tags. In my opinion, HTML tags are already easy to insert. The idea for Markdown is to make it easy to read, write, and edit prose. HTML is a publishing format; Markdown is a writing format. Thus, Markdown's formatting syntax only addresses issues that can be conveyed in plain text.

如果你关心元素之间的填充,你关心的是格式化,而不是写入,这超出了预期的范围降价。是的,可以恢复到原始 HTML(可能带有嵌入式内联 CSS)以强制执行您想要的 格式 ,但这正是它应该的方式工作。事实上,上述引用文件的下一段指出:

For any markup that is not covered by Markdown's syntax, you simply use HTML itself. There's no need to preface it or delimit it to indicate that you're switching from Markdown to HTML; you just use the tags.

因此,解决您的问题的适当方法是使用原始 HTML and/or CSS,而不是使用一些特殊的 Markdown 语法。

Markdown 中的换行符是 "two or more spaces at the end of the line"。

简答:行尾两个空格

详情:

我提供更新的答案,因为@xof 的答案虽然不完整但正确 (per the docs):

When you do want to insert a <br /> break tag using Markdown, you end a line with two or more spaces, then type return.

Yes, this takes a tad more effort to create a <br />, but a simplistic “every line break is a <br />” rule wouldn’t work for Markdown. Markdown’s email-style blockquoting and multi-paragraph list items work best — and look better — when you format them with hard breaks.

此外,这还有一个额外的好处,即避免文档不必要地成为 markdown 和 HTML 的混合体。这保留了可读性,因为当 Markdown 查看器不可用时,例如在终端 window.

只有一件事:不要在尾随空格上做全局 trim,这是源代码的习惯,否则你会丢失重要的格式。

根据 Markdown 指南,为了强制换行,您需要在行尾添加 2 个空格,然后是 return 键。

在此处查看指南。 https://markdown-guide.readthedocs.io/en/latest/basics.html#line-return

我有时会在我的降价文档中简单地输入回车 return 时出现奇怪的行为。但是按照本指南,我可以通过在行尾添加 2 个空格来强制换行。

行尾的反斜杠 \ 似乎也有效。并且不会通过尾随 space 删除来删除。