parser_core.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /** internal
  2. * class Core
  3. *
  4. * Top-level rules executor. Glues block/inline parsers and does intermediate
  5. * transformations.
  6. **/
  7. 'use strict';
  8. var Ruler = require('./ruler');
  9. var _rules = [
  10. [ 'normalize', require('./rules_core/normalize') ],
  11. [ 'block', require('./rules_core/block') ],
  12. [ 'inline', require('./rules_core/inline') ],
  13. [ 'linkify', require('./rules_core/linkify') ],
  14. [ 'replacements', require('./rules_core/replacements') ],
  15. [ 'smartquotes', require('./rules_core/smartquotes') ]
  16. ];
  17. /**
  18. * new Core()
  19. **/
  20. function Core() {
  21. /**
  22. * Core#ruler -> Ruler
  23. *
  24. * [[Ruler]] instance. Keep configuration of core rules.
  25. **/
  26. this.ruler = new Ruler();
  27. for (var i = 0; i < _rules.length; i++) {
  28. this.ruler.push(_rules[i][0], _rules[i][1]);
  29. }
  30. }
  31. /**
  32. * Core.process(state)
  33. *
  34. * Executes core chain rules.
  35. **/
  36. Core.prototype.process = function (state) {
  37. var i, l, rules;
  38. rules = this.ruler.getRules('');
  39. for (i = 0, l = rules.length; i < l; i++) {
  40. rules[i](state);
  41. }
  42. };
  43. Core.prototype.State = require('./rules_core/state_core');
  44. module.exports = Core;