jsantell / poet

A node.js blog engine
jsantell.github.io/poet
MIT License
605 stars 146 forks source link

added syntax highlighting with pigmentize #108

Closed sebpiq closed 9 years ago

ChrisMcKenzie commented 10 years ago

This is a great Idea I wonder if it would be better to have this as an option that you could use different highlighters and optionally turn it off completely.

Also could you write some unit tests for this?

sebpiq commented 9 years ago

Hmm ... in fact now that I look at the docs more you probably don't need this at all, since you can just do :

var markdown = require('marked')
  , pygmentize = require('pygmentize-bundled')

markdown.setOptions({
  sanitize: false,
  pedantic: true,
  highlight: function (code, lang, callback) {
    pygmentize({ lang: lang, format: 'html' }, code, function (err, result) {
      callback(err, result.toString())
    })
  }
})

// Override markdown template renderer to add syntax highlighting
poet.addTemplate({
  ext: 'md', 
  fn: function(options, callback) {
    markdown(options.source, callback)
  }
})

I'd suggest to add it to the docs as an example though, because I'm assuming many people using this project will need syntax highlighting ;)

And in fact, it is better IMO to provide hooks and not add more functionalities. The library is now quite lean and allows you to do this, so it's great!