2013-04-02 18 views
1

我們使用Bluecloth在rails網站上進行文本格式設置,但我遇到了一些電子郵件地址的問題。當他們在地址中使用雙下劃線BlueCloth將其轉換爲EM標籤時。使用BlueCloth如何關閉部分文字的降價?

在軌控制檯:

BlueCloth::new("[email protected]").to_html 
"<p>[email protected]</p>" 

以單下劃線的電子郵件地址工作正常,但是當有地址兩個下劃線將下劃線改爲EM標籤:

BlueCloth::new("[email protected]").to_html 
"<p>bob<em>jones</em>[email protected]</p>" 

我需要爲文本的其餘部分設置格式,但我需要關閉電子郵件地址。我覺得我曾經可以使用notextile標籤,但似乎不再適用。

BlueCloth::new("<notextile> [email protected] </notextile>").to_html 
"<p><notextile> bob<em>jones</em>[email protected] </notextile></p>" 

任何人都知道如何處理這個?我們使用的是bluecloth 2.2.0版。

回答

2

一種選擇是將:relaxed設置切換到true

BlueCloth.new('[email protected]', relaxed: true).to_html 

The option documentation is available online但選項名稱和它們映射到底層C庫選項的方式並不總是顯而易見的。

如果你想在你需要的字強調在一些地方使用的默認選項的文本,但不是別人,你可以explicitly escape the underscores

escaped_email = '[email protected]'.gsub('_', '\_') 
BlueCloth.new(escaped_email).to_html 
+0

非常感謝!這對我有用。 –

0

你爲什麼不使用字符串插值?

BlueCloth::new("don't format this: %s").to_html % '[email protected]' 
=> "<p>don't format this: [email protected]</p>" 

除非你不知道你想保留原始字符串的位置,這將是...奇怪。

+0

感謝您的迴應,這是一個好主意,但內容來自外部來源,所以我無法控制它。 –