Pygments is Widely Known as Powerful Syntax Highlighter in Python. Here is a ready to use WordPress Pygments Syntax Highlighting Plugin. Those who do not know about Syntax Highlighting, can read this basic article on Syntax Highlighting. There are many ways to detect the programing language and Highlight properly. Those who are not aware about Pygments Syntax Highlighting, can read about it from official website :
1 | http://pygments.org/ |
Right now, probably the most powerful or usable Syntax Highlighting Plugin in WordPress is Crayon, which we use. But, for more solid code oriented blogs, Pygments is possibly a need.
Pygments Syntax Highlighting in WordPress
Actually Derek Simkowiak wrote the Plugin, but he for some reason has not updated it for more than two years. His blog itself is running WordPress 3.3. There are lot of changes since then, so you can grab and complain from my GitHub Repository :
---
1 | https://github.com/AbhishekGhosh/WordPress-Pygments |
You need to install python-pygments first (for deb based server) :
1 | sudo apt-get install python-pygments |
Then, install this plugin. As written there; the usage pattern is like this :
1 | [pyg language="python" style="monokai" linenos="table" hl_lines="7 8 9" ] code here [/pyg] |
GeSHi actually misses line numbers :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # # Here is some raw Python, pasted directly into the page: # # For every line... for line in lines: # ...print it out if it's not blank: if line != "": print line else: result = blank_line_handler() print "Blank line found, handler returned: %s" % result |
But with Pygments :
Another example is with mentioning the Theme name :
1 | [pyg language="html+php" style="monokai" ] |
Other things are written in the WordPress Pygments repo in details.
Tagged With highlight word python , Pygments Syntax Highlighting , rst2html5 pygments css ready , The name of the Pygments (syntax highlighting) style to use