highlightFile.js 475 B

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