aboutsummaryrefslogtreecommitdiff
path: root/index.js
blob: c14d8948cf339f24c698e4db4328d747ea0abf12 (plain)
  1. 'use strict';
  2. var fs = require('fs');
  3. var path = require('path');
  4. var extractSpecTests = function(data) {
  5. var examples = [];
  6. var current_section = "";
  7. var example_number = 0;
  8. var tests = data
  9. .replace(/\r\n?/g, "\n") // Normalize newlines for platform independence
  10. .replace(/^<!-- END TESTS -->(.|[\n])*/m, '');
  11. tests.replace(/^`{32} example\n([\s\S]*?)^\.\n([\s\S]*?)^`{32}$|^#{1,6} *(.*)$/gm,
  12. function(_, markdownSubmatch, htmlSubmatch, sectionSubmatch){
  13. if (sectionSubmatch) {
  14. current_section = sectionSubmatch;
  15. } else {
  16. example_number++;
  17. examples.push({markdown: markdownSubmatch,
  18. html: htmlSubmatch,
  19. section: current_section,
  20. number: example_number});
  21. }
  22. });
  23. return examples;
  24. };
  25. exports.text = fs.readFileSync(path.join(__dirname, 'spec.txt'), 'utf8');
  26. exports.tests = extractSpecTests(exports.text);