From 7738fefabc6f717c1d5e2459dabadea0fa588def Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 4 May 2013 10:41:23 +0100 Subject: Add document matchers for lists --- lib/document-matchers.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/document-matchers.js b/lib/document-matchers.js index a40bde7..820d6c2 100644 --- a/lib/document-matchers.js +++ b/lib/document-matchers.js @@ -11,11 +11,30 @@ function run(styleName) { } function Matcher(elementType, styleName) { - this.elementType = elementType; - this.styleName = styleName; + this._elementType = elementType; + this._styleName = styleName; } Matcher.prototype.matches = function(element) { - return element.type === this.elementType && - (!this.styleName || element.styleName === this.styleName); + return element.type === this._elementType && + (!this._styleName || element.styleName === this._styleName) && + (!this._listIndex || isList(element, this._listIndex, this._listIsOrdered)); +} + +Matcher.prototype.orderedList = function(levelIndex) { + this._listIndex = levelIndex; + this._listIsOrdered = true; + return this; +} + +Matcher.prototype.unorderedList = function(levelIndex) { + this._listIndex = levelIndex; + this._listIsOrdered = false; + return this; +} + +function isList(element, levelIndex, isOrdered) { + return element.numbering && + element.numbering.level == levelIndex && + element.numbering.isOrdered == isOrdered; } -- cgit v1.2.3