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

setting options requires one setting all options #88

Closed
arve0 opened this issue May 29, 2019 · 2 comments · Fixed by #89
Closed

setting options requires one setting all options #88

arve0 opened this issue May 29, 2019 · 2 comments · Fixed by #89

Comments

@arve0
Copy link
Owner

arve0 commented May 29, 2019

Code to reproduce:

const md = require('markdown-it')();
const markdownItAttrs = require('./');

md.use(markdownItAttrs, {
  allowedAttributes: ['id', 'class', /^regex.*$/]
});

let src = 'asdf *asd*{.c} khg';

let res = md.render(src);

console.log(res);  // eslint-disable-line

Current result: Throws error

/Users/arve/git/markdown-it-attrs/utils.js:227
  return s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
           ^

TypeError: Cannot read property 'replace' of undefined
    at Object.escapeRegExp (/Users/arve/git/markdown-it-attrs/utils.js:227:12)
    at module.exports.options (/Users/arve/git/markdown-it-attrs/patterns.js:11:35)
    at Function.attributes (/Users/arve/git/markdown-it-attrs/index.js:16:20)
    at MarkdownIt.use (/Users/arve/git/markdown-it-attrs/node_modules/markdown-it/lib/index.js:496:10)
    at Object.<anonymous> (/Users/arve/git/markdown-it-attrs/debug.js:5:4)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)

Expected result: Should not throw error.

Reported in https://github.com/kidonng/markdown-it-attrs/pull/1

@arve0
Copy link
Owner Author

arve0 commented May 29, 2019

@kidonng Thanks for reporting! I've made an example where you can explore Object.assign: https://jsbin.com/pixiyop/edit?js,console

Happy hacking 😊

@arve0
Copy link
Owner Author

arve0 commented May 29, 2019

Released in v2.4.1

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.

1 participant