exports.paragraph = paragraph; exports.run = run; function paragraph(styleId) { return new Matcher("paragraph", styleId); } function run(styleId) { return new Matcher("run", styleId); } function Matcher(elementType, styleId) { this._elementType = elementType; this._styleId = styleId; } Matcher.prototype.matches = function(element) { return element.type === this._elementType && (this._styleId === undefined || element.styleId === this._styleId) && (this._listIndex === undefined || isList(element, this._listIndex, this._listIsOrdered)); }; Matcher.prototype.orderedList = function(levelIndex) { return this.list({isOrdered: true, levelIndex: levelIndex}); }; Matcher.prototype.unorderedList = function(levelIndex) { return this.list({isOrdered: false, levelIndex: levelIndex}); }; Matcher.prototype.list = function(options) { this._listIndex = options.levelIndex; this._listIsOrdered = options.isOrdered; return this; }; function isList(element, levelIndex, isOrdered) { return element.numbering && element.numbering.level == levelIndex && element.numbering.isOrdered == isOrdered; }