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

error with marked + highlight.js #787

Closed
stla opened this issue Aug 18, 2016 · 2 comments · Fixed by #682
Closed

error with marked + highlight.js #787

stla opened this issue Aug 18, 2016 · 2 comments · Fixed by #682

Comments

@stla
Copy link

stla commented Aug 18, 2016

Hello,
Following this post.

$ node marked_test.js  > xx.txt
/home/stla/Github/temp/node_modules/marked/lib/marked.js:1227
    throw e;
    ^

TypeError: src.replace is not a function
Please report this to https://github.com/chjj/marked.
    at Lexer.lex (/home/stla/Github/temp/node_modules/marked/lib/marked.js:138:6)
    at Function.Lexer.lex (/home/stla/Github/temp/node_modules/marked/lib/marked.js:129:16)
    at marked (/home/stla/Github/temp/node_modules/marked/lib/marked.js:1219:31)
    at Object.<anonymous> (/home/stla/Github/temp/marked_test.js:14:14)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)

Node version:

$ node -v
v4.5.0

Source file:

var fs     = require('fs');
var hljs   = require('highlight.js');
var marked = require('marked');

var markdownString = fs.readFileSync('./node_modules/marked/README.md');

marked.setOptions({
  highlight: function (code) {
    return hljs.highlightAuto(code).value;
  }
});

var output = marked(markdownString);

console.log(output);
@Feder1co5oave
Copy link
Contributor

You're providing marked with a raw buffer. Use

var markdownString = fs.readFileSync('./node_modules/marked/README.md', 'utf8');

Reference: https://nodejs.org/api/fs.html#fs_fs_readfile_file_options_callback

@joshbruce
Copy link
Member

#983

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

Successfully merging a pull request may close this issue.

3 participants