From ec837dc5c639efa92fb676dc90c008ad7cfff58e Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 22 Apr 2014 13:38:46 +0100 Subject: Simplify document matcher parsing --- lib/document-matchers.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'lib/document-matchers.js') diff --git a/lib/document-matchers.js b/lib/document-matchers.js index f116d3f..0846513 100644 --- a/lib/document-matchers.js +++ b/lib/document-matchers.js @@ -1,18 +1,34 @@ +var _ = require("underscore"); + exports.paragraph = paragraph; exports.run = run; -function paragraph(styleId) { - return new Matcher("paragraph", styleId); +function paragraph(options) { + options = options || {}; + if (_.isString(options)) { + // TODO: this is deprecated, remove usages + options = {styleId: options}; + } + return new Matcher("paragraph", options); } -function run(styleId) { - return new Matcher("run", styleId); +function run(options) { + options = options || {}; + if (_.isString(options)) { + // TODO: this is deprecated, remove usages + options = {styleId: options}; + } + return new Matcher("run", options); } -function Matcher(elementType, styleId) { +function Matcher(elementType, options) { this._elementType = elementType; - this._styleId = styleId; + this._styleId = options.styleId; + if (options.list) { + this._listIndex = options.list.levelIndex; + this._listIsOrdered = options.list.isOrdered; + } } Matcher.prototype.matches = function(element) { -- cgit v1.2.3