文本区域中的 HAML 额外空格

HAML Extra Spaces in Textarea

我 运行 遇到了一个我似乎无法破译的问题。

我正在尝试将文本放入 Rails 应用程序的文本区域中。我有一个包含文本的变量,它是一个多行字符串,由读取文件的内容组成。这是 string by the end of the reading of the file. However, the string ends up being put in the text area looking like this.

我的猜测是,这是由于 textarea 如何解析换行符。将它们全部替换为 <br><br /> 会将标签呈现为纯文本。听起来好像有一个简单的解决方案,但我不确定如何解决它。

编辑:根据请求,这里是带有文本区域的代码。它是用 HAML 编写的,对此深表歉意,我找不到一个 HAML 到 HTML 的有效转换器(或者我不擅长谷歌搜索)。

%textarea{:name => "user_css", :width => "90%", :rows => "30", :style => "font-family:Courier; font-size:12; white-space:pre-wrap"}
        = css_contents

一些你可以尝试的事情
1. 使用 HAML 的 :preservefind_and_preserve 助手

%textarea{:name => "user_css", :width => "90%", :rows => "30", :style => "font-family:Courier; font-size:12; white-space:pre-wrap"}
   :preserve 
       = css_contents

2。使用 HAML's tilde (~)

%textarea{:name => "user_css", :width => "90%", :rows => "30", :style => "font-family:Courier; font-size:12; white-space:pre-wrap"}
   ~ css_contents    

3。写在同一行

%textarea{..}= "#{css_contents}"