highlightFile.js 476 B

12345678910111213141516171819202122232425
  1. 'use strict'
  2. var fs = require('fs')
  3. var highlight = require('./highlight')
  4. function isFunction(obj) {
  5. return toString.call(obj) === '[object Function]'
  6. }
  7. module.exports = function highlightFile(fullPath, opts, cb) {
  8. if (isFunction(opts)) {
  9. cb = opts
  10. opts = { }
  11. }
  12. opts = opts || { }
  13. fs.readFile(fullPath, 'utf-8', function(err, code) {
  14. if (err) return cb(err)
  15. try {
  16. cb(null, highlight(code, opts))
  17. } catch (e) {
  18. cb(e)
  19. }
  20. })
  21. }