eudicots / Cactus

Static site generator for designers. Uses Python and Django templates.
BSD 3-Clause "New" or "Revised" License
3.46k stars 314 forks source link

Syntax highlight using Pygments #225

Open vbrilon opened 8 years ago

vbrilon commented 8 years ago

I'd like to add support for Pygment code syntax highlighting -- but I am having trouble figuring out where in the plugin lifecycle this needs to happen. Any plugin documentation or examples you can point me to @koenbok please?

ghost commented 8 years ago

would be really great to add pygments here :+1:

vbrilon commented 8 years ago

@vyscond -- I made a pull request with my changes. It's a tiny piece of code, so should be easy to integrate it into your own setup. Grab it and let me know what you think.

vbrilon commented 8 years ago

The pull request is here: https://github.com/koenbok/Cactus/pull/227

ghost commented 8 years ago

Got it. But i think you need to add pygments to dependencies. Right now you plugin kind assumes that we have pygments installed as a global package. Right?

vbrilon commented 8 years ago

Correct. I've not defined dependencies properly but the import statements are pretty clear :)

dwightgunning commented 8 years ago

Is the intention to syntax highlight markdown?

I'm currently achieving this by adding the fenced-code-block extension to the markdown template tag (which detects and uses pygments when available):

   {% filter markdown:"fenced-code-blocks" %}
   ```python
   PAGE_URL = '{slug}/'
   PAGE_SAVE_AS = '{slug}/index.html'
   {% endfilter %}```

So there may not be any need for an additional cactus plugin.

ghost commented 8 years ago

in this case you installed pygments globally?

dwightgunning commented 8 years ago

I use a virtualenv for Cactus so I've got pygments installed in there. You could install it globally if you prefer.

The nice thing with the MD template tag and the (built in) fenced-code-blocks extension, there's no hard dependency on pygments.

ghost commented 8 years ago

I think this "problem"/"request" is more related to people using the mac app.

dwightgunning commented 8 years ago

@vyscond - oh right... in that case, yeah, install it globally or go hacking around inside the OS X application package.

We should start making use of 'labels'.... @krallin @koenbok - I'd be happy to help with that sort of housekeeping if it's possible to assign that role without giving out commit rights.

ghost commented 8 years ago

I can't think about any terrible thing right now about including pygments as default dependency on both environments. May add a app option too turn/switch on/off the pygment render. I think...

vbrilon commented 8 years ago

@vyscond This request/issue is not specific to the mac app at all

dwightgunning commented 8 years ago

@vyscond - I'd prefer to see it remain optional in the core cactus package. It's really an optional/extended feature. Once it's set as a dependency the matters of ongoing stability, compatibility, etc. become more critical.

As it currently stands, it's super simple to install pygments via pip and the python markdown engine will use it if it's available. If the markdown project deemed it essential for markdown authors, then we'd be picking it up via that dependency chain. Their approach seems to support my point above.

For the mac app, then it may be more logical to include pygments if the target audience are frequently writing markdown with code blocks. But that's a separate decision process anyways.