我希望看到以下文本(注意80个字符标记处的换行符):
This worked for a few months. Unfortunately, occasionally a test would time
out and fail after 18 seconds - maybe 1 in 100 test runs would fail with a
timeout. Normally when the tests fail you get back some kind of error message
- a Postgres constraint failure will print a useful message, or a Javascript
exception will bubble up, or Javascript will complain about an unhandled
rejection.在通过标记编辑器运行时,生成以下HTML:
<p>
This worked for a few months. Unfortunately, occasionally a test would time
out and fail after 18 seconds - maybe 1 in 100 test runs would fail with a
timeout. Normally when the tests fail you get back some kind of error message
- a Postgres constraint failure will print a useful message, or a Javascript
exception will bubble up, or Javascript will complain about an unhandled
rejection.
</p>当我通过cmark运行它时,我得到了以下结果:
<p>This worked for a few months. Unfortunately, occasionally a test would time
out and fail after 18 seconds - maybe 1 in 100 test runs would fail with a
timeout. Normally when the tests fail you get back some kind of error message</p>
<ul>
<li>a Postgres constraint failure will print a useful message, or a Javascript
exception will bubble up, or Javascript will complain about an unhandled
rejection.</li>
</ul>
<p>With this error we didn't get any of those. We also observed it could happen
anywhere - it didn't seem to correlate with any individual test or test file.</p>这似乎是不正确的--我绝对不希望列表从段落的中间开始。这是规范中的一个问题,还是我可以做些不同的事情来避免触发这种行为?
发布于 2016-05-27 00:15:31
简而言之,使用适当的字符,可能是emdash,而不是连字符。
规范states
在CommonMark中,列表可以中断段落。也就是说,从下面的列表中分隔段落时不需要空行:
Foo - bar - baz Foo bar baz
后来解释说,这是因为CommonMark遵守principle of uniformity。具体地说,以列表标记开头的行始终是列表项,而与周围的行无关。规范甚至承认Markdown在这里的行为不同,特别是为了避免您遇到的问题,但CommonMark更倾向于一致性而不是合理性/易用性(显然)。
因此,解决方案是,当行不是列表项时,永远不要以列表标记开始行。虽然您可以小心地对行进行换行,但将来的编辑可能会重新引入该问题。幸运的是,连字符(Unicode char \u2010,键盘上的字符和用作列表标记的字符)在正常的英语语法中很少像列表标记那样使用。具体地说,连字符后面永远不能跟空格,这是列表标记所必需的。如果您想在字符后面加上空格,您可能需要一个尾号(Unicode char \u2013)、emdash (Unicode char \u2014)或减号(Unicode char \u2212) (有关说明,请参阅this question )。因此,使用适当的字符就可以避免这个问题。
让我们试一试:
This worked for a few months. Unfortunately, occasionally a test would time
out and fail after 18 seconds — maybe 1 in 100 test runs would fail with a
timeout. Normally when the tests fail you get back some kind of error message
— a Postgres constraint failure will print a useful message, or a Javascript
exception will bubble up, or Javascript will complain about an unhandled
rejection.CommonMark的输出结果是:
<p>This worked for a few months. Unfortunately, occasionally a test would time
out and fail after 18 seconds — maybe 1 in 100 test runs would fail with a
timeout. Normally when the tests fail you get back some kind of error message
— a Postgres constraint failure will print a useful message, or a Javascript
exception will bubble up, or Javascript will complain about an unhandled
rejection.</p>注意,对于第一次出现,我使用了HTML实体(—),而对于第二次出现,我直接使用了emdash字符(—)。CommonMark将HTML实体转换为emdash字符,并原封不动地通过传递文字字符。就可读性而言,实际的字符当然更好,尽管很难键入,因为它不会出现在大多数键盘上。
如果使用SmartyPants,则可以使用双连字符(--)或三连字符(---),SmartyPants将它们分别转换为尾连字符和短划线。只要连字符之间没有空格,双连字符和三连字符就不会触发列表。
发布于 2016-05-26 23:15:10
有没有什么我可以做的不同的事情来避免触发这种行为?
以下内容应避免使用该列表:
This worked for a few months. Unfortunately, occasionally a test would time
out and fail after 18 seconds - maybe 1 in 100 test runs would fail with a
timeout. Normally when the tests fail you get back some kind of error
message - a Postgres constraint failure will print a useful message, or a
Javascript exception will bubble up, or Javascript will complain about an
unhandled rejection.https://stackoverflow.com/questions/37464769
复制相似问题