让语法荧光笔与我的 Rails 博客一起使用

发布于 2024-12-21 20:22:48 字数 3055 浏览 2 评论 0原文

我正在尝试使用语法荧光笔使我的嵌入代码看起来很棒。我可以在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苏佲洛 2024-12-28 20:22:48

非常感谢任何帮助!

对于 Rails 上的语法突出显示,我建议通过 gem highlighting 使用 prism.js

集成非常简单。您可以在此处阅读有关如何与 Rails 集成的更多信息 https://github.com/ytbryan/highlighting

Any help would be much obliged!

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文