2016-05-26 27 views
0

中間名單我希望下面的文字(在80個字符標記注換行符):CommonMark插入段

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> 

哪似乎不正確 - 我絕對不希望列表在段落中間開始。這是規範中的問題,還是有什麼我可以做不同的事情不觸發這種行爲?

+0

有趣。這是Markdown的分歧。參見[Babelmark](http://johnmacfarlane.net/babelmark2/?normalize=1&text=This+worked+for+a+few+months.+Unwanted%2C+occasionally+a+test+would+time%0Aout+and +失敗+後+ 18 +秒+ - +也許+ 1 +在+ 100 +測試+ +中+測試+失敗時運行+會+失敗+與+一%0Atimeout +通常+ +你+拿到+背部+一些+種+ +錯誤消息%+ 0A- + A +的Postgres +約束+失敗+意願+打印+ A +有用+消息%2C +或+ A +的Javascript%0Aexception +將+氣泡+向上%2C +或+ Javascript +會+抱怨+關於+未處理的%0Arejection。) – Waylan

回答

0

有沒有什麼我可以做不同的不觸發這種行爲?

下應避免名單:

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. 
+0

正確的,你可以使用連字符,所以它不會開始行,但這並不能防止問題在未來出現。 –

+0

同意,這就是爲什麼我特別提出了一種避免這種行爲的替代方案。 – mdickin

+1

@mdickin問題在於,在未來的編輯中,可能會重新包裝段落,並重新引入問題。這不是一個解決方案,只是一個臨時的解決方法。在我的回答中,我提供了一個解決方案,未來的編輯不會重新提出問題。 – Waylan

2

總之,使用正確的字符,可能是一個emdash,而不是一個連字符。

該規範states

在CommonMark,列表可以中斷一個段落。也就是說,不需要空行一個段落從下面的列表中分離:

Foo 
- bar 
- baz 


<p>Foo</p> 
<ul> 
<li>bar</li> 
<li>baz</li> 
</ul> 

據後來解釋說,這是因爲CommonMark粘附在principle of uniformity。具體而言,以列表標記開頭的行總是列表項,而不管任何環繞行。該規範甚至承認,Markdown在這裏的行爲有所不同,專門用於避免您遇到的問題,但CommonMark傾向於統一/合理/易用性(顯然)。

所以解決方案是永遠不會用列表標記開始一行,當該行不是列表項。儘管您可以小心翼翼地包裝線條,但未來的編輯可能會重新提出問題。幸運的是,連字符(Unicode char \u2010,它是鍵盤上的字符和用作列表標記的字符)很少用於正確的英語語法中,就像列表標記一樣。具體來說,連字符不應該跟隨空格,這是列表標記所必需的。如果你想跟隨字符的空格,你可能需要一個endash(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 &mdash; 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實體(&mdash;),而爲我所用的第二次出現直接輸入emdash字符()。 CommonMark將HTML實體轉換爲emdash字符,並通過不變的方式傳遞字面字符。爲了便於閱讀,實際的字符當然更好,雖然很難打字,因爲它不出現在大多數鍵盤上。

如果使用SmartyPants,你可以使用雙(--)或三(---)連字符,其聰明的傢伙分別轉換爲endashes和emdashes。而且,只要連字符之間沒有空格,雙重和三重連字符就不會觸發列表。