Pelican: Customizing pygments code block using Markdown instead of rst?

Created on 21 Jan 2014  路  1Comment  路  Source: getpelican/pelican

Hello,

My entire blog is written in Markdown - I was using Octopress, now I'm working on switching to Pelican as it's

  1. Actively developed
  2. Not written in Ruby

The problem is that I want to customize the pygments options for all my code blocks without having to go through and convert every single post into RST format. Changing PYGMENTS_RST_OPTIONS in pelicanconf.py doesn't seem to affect anything, and the docs only mention how to do things like turn on line numbers, etc, for the RST format.

Is there any way to go about this without writing a new plugin?

Thanks so much!

Most helpful comment

Ok, I kind of sorted what I needed. Using:

MD_EXTENSIONS = ['fenced_code', 'codehilite(css_class=highlight, linenums=True)', 'extra']

in my pelicanconf.py file, I was able to enable line numbering and fenced code block in markdown files. It's not 100% what I wanted, but it's good enough for now. The MD_EXTENSIONS setting couldn't hurt to be documented in the Getting Started docs on syntax highlighting.

From the markdown python source:

codehilite options:

  • linenums: (Boolean) Set line numbering to 'on' (True), 'off' (False) or 'auto'(None).
    Set to 'auto' by default.
  • guess_lang: (Boolean) Turn language auto-detection 'on' or 'off' (on by default).
  • css_class: Set class name of wrapper div ('codehilite' by default).
  • hl_lines: (List of integers) Lines to emphasize, 1-indexed.

Using the fenced_code extension enables you to use GitHub-style code blocks:

``````

print 'Hello world!'

``````

>All comments

Ok, I kind of sorted what I needed. Using:

MD_EXTENSIONS = ['fenced_code', 'codehilite(css_class=highlight, linenums=True)', 'extra']

in my pelicanconf.py file, I was able to enable line numbering and fenced code block in markdown files. It's not 100% what I wanted, but it's good enough for now. The MD_EXTENSIONS setting couldn't hurt to be documented in the Getting Started docs on syntax highlighting.

From the markdown python source:

codehilite options:

  • linenums: (Boolean) Set line numbering to 'on' (True), 'off' (False) or 'auto'(None).
    Set to 'auto' by default.
  • guess_lang: (Boolean) Turn language auto-detection 'on' or 'off' (on by default).
  • css_class: Set class name of wrapper div ('codehilite' by default).
  • hl_lines: (List of integers) Lines to emphasize, 1-indexed.

Using the fenced_code extension enables you to use GitHub-style code blocks:

``````

print 'Hello world!'

``````

Was this page helpful?
0 / 5 - 0 ratings