aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-05-04 10:41:23 +0100
committerMichael Williamson <mike@zwobble.org>2013-05-04 10:41:23 +0100
commit7738fefabc6f717c1d5e2459dabadea0fa588def (patch)
tree7c03b079117eddcf063449311ae127fd2d9a7217 /lib
parentcdf71ffdfa56ed698513b8a1d424c73967816c38 (diff)
Add document matchers for lists
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;
}