Skip to content

Commit

Permalink
fix: call walkTokens when calling marked with a callback(#2060)
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed May 21, 2021
1 parent 29a301b commit 1d97308
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/marked.js
Expand Up @@ -51,6 +51,9 @@ function marked(src, opt, callback) {

if (!err) {
try {
if (opt.walkTokens) {
marked.walkTokens(tokens, opt.walkTokens);
}
out = Parser.parse(tokens, opt);
} catch (e) {
err = e;
Expand Down
14 changes: 14 additions & 0 deletions test/unit/marked-spec.js
Expand Up @@ -183,6 +183,20 @@ describe('use extension', () => {
expect(walked).toBe(2);
});

it('should use walkTokens in async', (done) => {
let walked = 0;
const extension = {
walkTokens(token) {
walked++;
}
};
marked.use(extension);
marked('text', () => {
expect(walked).toBe(2);
done();
});
});

it('should use options from extension', () => {
const extension = {
headerIds: false
Expand Down

1 comment on commit 1d97308

@vercel
Copy link

@vercel vercel bot commented on 1d97308 May 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.