Do I need to generate a css file from Pygments for my jekyll blog, to enable colorful code snippet?

梦想的初衷 提交于 2019-11-30 05:02:07

You need to include syntax.css

You can take the sample from my repo https://github.com/madhur/madhur.github.com/blob/master/files/css/syntax.css

and then customize it according to your theme. Mine is customized for dark backgrounds.

Alan W. Smith

Yes, you need to either install or create CSS classes to make the code highlighting work Pygments does visible. After installing Pygments, this can be done by running the following from the command line:

pygmentize -S default -f html > pygments.css

This will create a pygments.css file with the default in your current directory; pygments -L style will list all available styles.

You can either move this into your HTML tree and call it with a corresponding:

<link rel="stylesheet" type="text/css" href="/path/to/pygments.css">

Or, copy the contents of pygments.css and place it in an existing style sheet. That will get you started. You can edit the CSS from there to customize as appropriate.


Two notes:

  1. You've probably already done this, but for the benefit of people who are new to Jekyll and Pygments, you'll probably also have to add pygments: true to your _config.yml file to get Pygments working. (Or, run jekyll with jekyll --pygments which has the same effect.)

  2. The original Jekyll installation documentation wasn't very clear about how to get Pygments working when this question was asked. I added 'Pygments Usage' section since then to hopefully help clear things up there as well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!