CodeRay 添加了不正确的缩进

CodeRay adds incorrect indentation

我正在使用 CodeRay 版本 1.1.1 呈现 ruby 文件。但是,它添加了大量额外的空格来缩进除第一行以外的所有行。

作为 MCVE,我有一个名为 something.rb 的文件,其内容为:

# This comment will not be indented
# This comment WILL be indented

在我的控制器中:

contents = File.read('something.rb')
@syntax_highlighted = CodeRay.scan(contents, :ruby).div

在视图中,我有

= raw @syntax_highlighted

但是,对于我收到的输出,如下所示:

这是由于 HAML 弄乱了您的空格造成的。请参阅关于 Whitespace Preservation.

的 HAML 文档

Sometimes you don’t want Haml to indent all your text. For example, tags like pre and textarea are whitespace-sensitive; indenting the text makes them render wrong.

您需要使用 ~ 而不是通常的 =,因此您的视图将是:

~ raw @syntax_highlighted