aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/document-matchers.js27
1 files changed, 23 insertions, 4 deletions
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;
}