Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlighter function has no callback method #193

Closed
jbrooksuk opened this issue Jul 12, 2013 · 3 comments
Closed

Highlighter function has no callback method #193

jbrooksuk opened this issue Jul 12, 2013 · 3 comments

Comments

@jbrooksuk
Copy link

I'm using the example for pygmetize-bundled where you pass a callback through to highlight:

highlight: function (code, lang, callback) {
  pygmentize({ lang: lang, format: 'html' }, code, function (err, result) {
    callback(err, result.toString());
  });
}

But I get this error:

callback(err, result.toString());                            │···················
                        ^                                                            │···················
TypeError: undefined is not a function                                               │···················
    at /var/www/bloot/lib/routes.js:22:4                                             │···················
    at ChildProcess.exitClose (/var/www/bloot/node_modules/pygmentize-bundled/index.j│···················
s:24:13)                                                                             │···················
    at ChildProcess.EventEmitter.emit (events.js:98:17)                              │···················
    at maybeClose (child_process.js:735:16)                                          │···················
    at Socket.<anonymous> (child_process.js:948:11)                                  │···················
    at Socket.EventEmitter.emit (events.js:95:17)                                    │···················
    at Pipe.close (net.js:451:12)   
@ChrisWren
Copy link
Contributor

Are you using the async version of marked? Look at the example in usage where the second argument to the marked function is a callback.

@smagch
Copy link

smagch commented Aug 17, 2013

As @ChrisWren said, you should pass arguments with 3 arity in order to do asynchronous stuff. Take a look at an API here
https://github.com/chjj/marked#markedmarkdownstring-options-callback

var marked = require('marked');
var str = require('fs').readFileSync('./foo.js').toString();
var options = {
  gfm: true,
  highlight: function (code, lang, callback) {
    pygmentize({ lang: lang, format: 'html' }, code, function (err, result) {
      if (err) return callback(err);
      callback(null, result.toString());
    });
  }
};

var html;
// It'll throw error
// html = marked(str);
marked(str, options, function(err, result) {
  html = result;
});

I'm writing this because I've just got the same error and looked around docs and issues.

@supersheep
Copy link

options here should be optional, I've made try to fix this, take a look :) #260

@tomtheisen tomtheisen mentioned this issue Apr 25, 2018
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants