parser_core.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. // `text_join` finds `text_special` tokens (for escape sequences)
  17. // and joins them with the rest of the text
  18. [ 'text_join', require('./rules_core/text_join') ]
  19. ];
  20. /**
  21. * new Core()
  22. **/
  23. function Core() {
  24. /**
  25. * Core#ruler -> Ruler
  26. *
  27. * [[Ruler]] instance. Keep configuration of core rules.
  28. **/
  29. this.ruler = new Ruler();
  30. for (var i = 0; i < _rules.length; i++) {
  31. this.ruler.push(_rules[i][0], _rules[i][1]);
  32. }
  33. }
  34. /**
  35. * Core.process(state)
  36. *
  37. * Executes core chain rules.
  38. **/
  39. Core.prototype.process = function (state) {
  40. var i, l, rules;
  41. rules = this.ruler.getRules('');
  42. for (i = 0, l = rules.length; i < l; i++) {
  43. rules[i](state);
  44. }
  45. };
  46. Core.prototype.State = require('./rules_core/state_core');
  47. module.exports = Core;