recheck.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { Lexer } from '../lib/marked.esm.js';
  2. import { check } from 'recheck';
  3. const { inline, block } = Lexer.rules;
  4. function checkRegexp(obj, name) {
  5. return Promise.all(Object.keys(obj).map(async(prop) => {
  6. const item = obj[prop];
  7. const itemName = `${name}.${prop}`;
  8. let source = '';
  9. let flags = '';
  10. if (item instanceof RegExp) {
  11. source = item.source;
  12. flags = item.flags;
  13. } else if (typeof item === 'string') {
  14. source = item;
  15. } else {
  16. return checkRegexp(item, itemName);
  17. }
  18. const gfm = itemName.includes('.gfm.');
  19. const pedantic = itemName.includes('.pedantic.');
  20. const recheckObj = await check(source, flags);
  21. if (recheckObj.status !== 'safe') {
  22. console.log(`// ${itemName}: /${recheckObj.source}/${recheckObj.flags}`);
  23. console.log(`// marked(${recheckObj.attack.pattern}, { pedantic: ${pedantic ? 'true' : 'false'}, gfm: ${gfm ? 'true' : 'false'} });`);
  24. }
  25. }));
  26. }
  27. console.log(`
  28. import { marked } from '../lib/marked.esm.js';
  29. const start = Date.now();
  30. `);
  31. await Promise.all([
  32. checkRegexp(inline, 'inline'),
  33. checkRegexp(block, 'block'),
  34. ]);
  35. console.log(`
  36. console.log(Date.now() - start);`);