62 lines
1.3 KiB
JavaScript
62 lines
1.3 KiB
JavaScript
/** internal
|
|
* class Core
|
|
*
|
|
* Top-level rules executor. Glues block/inline parsers and does intermediate
|
|
* transformations.
|
|
**/
|
|
'use strict';
|
|
|
|
|
|
var Ruler = require('./ruler');
|
|
|
|
|
|
var _rules = [
|
|
[ 'normalize', require('./rules_core/normalize') ],
|
|
[ 'block', require('./rules_core/block') ],
|
|
[ 'inline', require('./rules_core/inline') ],
|
|
[ 'linkify', require('./rules_core/linkify') ],
|
|
[ 'replacements', require('./rules_core/replacements') ],
|
|
[ 'smartquotes', require('./rules_core/smartquotes') ],
|
|
// `text_join` finds `text_special` tokens (for escape sequences)
|
|
// and joins them with the rest of the text
|
|
[ 'text_join', require('./rules_core/text_join') ]
|
|
];
|
|
|
|
|
|
/**
|
|
* new Core()
|
|
**/
|
|
function Core() {
|
|
/**
|
|
* Core#ruler -> Ruler
|
|
*
|
|
* [[Ruler]] instance. Keep configuration of core rules.
|
|
**/
|
|
this.ruler = new Ruler();
|
|
|
|
for (var i = 0; i < _rules.length; i++) {
|
|
this.ruler.push(_rules[i][0], _rules[i][1]);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Core.process(state)
|
|
*
|
|
* Executes core chain rules.
|
|
**/
|
|
Core.prototype.process = function (state) {
|
|
var i, l, rules;
|
|
|
|
rules = this.ruler.getRules('');
|
|
|
|
for (i = 0, l = rules.length; i < l; i++) {
|
|
rules[i](state);
|
|
}
|
|
};
|
|
|
|
Core.prototype.State = require('./rules_core/state_core');
|
|
|
|
|
|
module.exports = Core;
|