jekyll syntax highlighter not working

2019-06-08 18:00发布

问题:

I'm using jekyll and Github Pages to build my website. And I followed all the instructions on http://jekyllrb.com/docs/templates/#code-snippet-highlighting, however, the syntax highlighter within my post won't render. Below is the code:

{% highlight ruby %}
def print_hi(name)
  puts "Hi, #{name}"
end
print_hi('Tom')
#=> prints 'Hi, Tom' to STDOUT.
{% endhighlight %}

And I think the markdown file doesn't render properly, either. Can anyone tell me where I did wrong? You can check the post here: https://amir0320.github.io/blog/welcome-to-jekyll/

回答1:

This is happening because you are have a stale file called main.css inside the css folder of your Jekyll project, which is replacing the file generated by Jekyll from the SASS file.

i.e. Jekyll builds the css\main.scss and creates a file _site\css\main.css, but then it sees the file css\main.css and copies it to _site\css\main.css, replacing the initial file that was generated via SASS.

Solution: Delete this file css\main.css.



回答2:

try this in markdown file.

```ruby
YOUR CODE
```

if you can see <code> in output html source, but still highlight not working, that is css problem.