本文介绍了胭脂宝石未在格式化代码中显示换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遵循了使用 rouge
gem
到
需要胭脂"来源="def plus_two(x)\ n x + 2 \ nend"formatter = Rouge :: Formatters :: HTML.newformatter = Rouge :: Formatters :: HTMLLinewise.new(formatter,类:'line-%i')lexer =胭脂::: Lexers :: R.new@code = formatter.format(lexer.lex(源))
更多格式选项此处
I have followed minimal examples using the rouge
gem here (i.e. the documentation), as well as here and here.
Everything working, except that line breaks in the code aren't appearing.
To be explicit, code like this
def plus_two(x)
x + 2
end
has the colours highlighted correctly, but is rendered across one line, like so
def plus_two(x) x + 2 end
How can I make it render with the line breaks (just as in the code file)
解决方案
Change
require 'rouge'
source = "def plus_two(x)\n x + 2\nend"
formatter = Rouge::Formatters::HTML.new
lexer = Rouge::Lexers::R.new
@code = formatter.format(lexer.lex(source))
to
require 'rouge'
source = "def plus_two(x)\n x + 2\nend"
formatter = Rouge::Formatters::HTML.new
formatter = Rouge::Formatters::HTMLLinewise.new(formatter, class: 'line-%i')
lexer = Rouge::Lexers::R.new
@code = formatter.format(lexer.lex(source))
More formatting options here
这篇关于胭脂宝石未在格式化代码中显示换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!