让语法荧光笔与我的 Rails 博客一起使用
我正在尝试使用语法荧光笔使我的嵌入代码看起来很棒。我可以在 html 文件上执行此操作,但当我在 Rails 博客上尝试时,它不起作用。
我的直觉告诉我这与我的控制器有关:
<pre class="brush: ruby;">
puts "Do you use Facebook? (Y/N)"
</pre>
<p>
<b>Entry:</b>
</p>
<%=sanitize @thought.entry %>
但是顶部的 html 仍然运行得很好......
<!DOCTYPE html>
<html>
<head>
<title>Blog</title>
<script src="/assets/shCore.js?body=1" type="text/javascript"></script>
<script src="/assets/shBrushRuby.js?body=1" type="text/javascript"></script>
<link href="/assets/shCoreDefault.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<script type="text/javascript">SyntaxHighlighter.all();</script>
<meta content="authenticity_token" name="csrf-param" />
<meta content="1OAMJ6dGJ8c7CHunEe9IBkNrcIJwrfYdwtskSFRGvUQ=" name="csrf-token" />
</head>
<body>
<p id="notice"></p>
<p>
<b>Title:</b>
Facehook
</p>
<p>
<b>Entry:</b>
</p>
<pre class="brush: ruby;">
puts "Do you use Facebook? (Y/N)"
facehooked = gets
if facehooked == "Y" #upper- or lower-case?
puts "How many friends do you have?"
friends = gets
if friends > 30
puts "I asked how many friends you have. Not how many friends you have on Facebook. You are Facehooked."
elsif friends == 0
puts "I am sorry to hear that."
else
#How sociable are you in the real world?
#TODO - data-type checking
puts "Please answer the following questions with a number:\nHow many people would you like to see on a weekly basis?"
buddies = gets
puts "How many people do you happen to see on a weekly basis?"
acquaintances = gets
puts "How many people that you do not like do you have to see on a daily basis?"
forced = gets
puts "How many people would you love to see on a daily basis?"
true_friends = gets
people = buddies + acquaintances + forced + true_friends
#ratios
true_friends_to_buddies = true_friends / buddies
buddies_to_acquaintances = buddes / acquaintances
true_friends_to_acquaintances = true_friends / aquaintances
puts "How many 'friends' do you have on Facebook?"
facehooks = gets
if people == 0
puts "You are ninja. You drift among this world without a connection. Please do not kill me."
elsif people >= 500
puts "You are one social motherfucker!"
else
end
end
elsif facehooked == "N"
puts "You do not have a hook in your face. Congratulations."
else
puts "That question required a yes or no answer."
end
puts "You should follow @ricburton on Twitter - he likes talking to new people, making acquaintances and building friendships."
</pre>
<a href="/thoughts/1/edit">Edit</a> |
<a href="/thoughts">Back</a>
</body>
</html>
任何帮助将非常感激!
I am trying to use Syntax Highlighter to make my embedded code look great. I can do it on a html file but when I try on my rails blog it doesn't work.
My gut tells me it is something to do with my controller:
<pre class="brush: ruby;">
puts "Do you use Facebook? (Y/N)"
</pre>
<p>
<b>Entry:</b>
</p>
<%=sanitize @thought.entry %>
But the bit of html at the top is still running just fine...
<!DOCTYPE html>
<html>
<head>
<title>Blog</title>
<script src="/assets/shCore.js?body=1" type="text/javascript"></script>
<script src="/assets/shBrushRuby.js?body=1" type="text/javascript"></script>
<link href="/assets/shCoreDefault.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<script type="text/javascript">SyntaxHighlighter.all();</script>
<meta content="authenticity_token" name="csrf-param" />
<meta content="1OAMJ6dGJ8c7CHunEe9IBkNrcIJwrfYdwtskSFRGvUQ=" name="csrf-token" />
</head>
<body>
<p id="notice"></p>
<p>
<b>Title:</b>
Facehook
</p>
<p>
<b>Entry:</b>
</p>
<pre class="brush: ruby;">
puts "Do you use Facebook? (Y/N)"
facehooked = gets
if facehooked == "Y" #upper- or lower-case?
puts "How many friends do you have?"
friends = gets
if friends > 30
puts "I asked how many friends you have. Not how many friends you have on Facebook. You are Facehooked."
elsif friends == 0
puts "I am sorry to hear that."
else
#How sociable are you in the real world?
#TODO - data-type checking
puts "Please answer the following questions with a number:\nHow many people would you like to see on a weekly basis?"
buddies = gets
puts "How many people do you happen to see on a weekly basis?"
acquaintances = gets
puts "How many people that you do not like do you have to see on a daily basis?"
forced = gets
puts "How many people would you love to see on a daily basis?"
true_friends = gets
people = buddies + acquaintances + forced + true_friends
#ratios
true_friends_to_buddies = true_friends / buddies
buddies_to_acquaintances = buddes / acquaintances
true_friends_to_acquaintances = true_friends / aquaintances
puts "How many 'friends' do you have on Facebook?"
facehooks = gets
if people == 0
puts "You are ninja. You drift among this world without a connection. Please do not kill me."
elsif people >= 500
puts "You are one social motherfucker!"
else
end
end
elsif facehooked == "N"
puts "You do not have a hook in your face. Congratulations."
else
puts "That question required a yes or no answer."
end
puts "You should follow @ricburton on Twitter - he likes talking to new people, making acquaintances and building friendships."
</pre>
<a href="/thoughts/1/edit">Edit</a> |
<a href="/thoughts">Back</a>
</body>
</html>
Any help would be much obliged!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 Rails 上的语法突出显示,我建议通过 gem
highlighting
使用 prism.js集成非常简单。您可以在此处阅读有关如何与 Rails 集成的更多信息 https://github.com/ytbryan/highlighting
For syntax highlighting on rails, i would recommend using using prism.js via the gem
highlighting
The integration is extremely simple. You can read more on how to integrate with rails here https://github.com/ytbryan/highlighting