blob: e68134919661da5871ca500570271135c457c2de (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
exports.paragraph = paragraph;
exports.run = run;
function paragraph(styleName) {
return new Matcher("paragraph", styleName);
}
function run(styleName) {
return new Matcher("run", styleName);
}
function Matcher(elementType, styleName) {
this._elementType = elementType;
this._styleName = styleName;
}
Matcher.prototype.matches = function(element) {
return element.type === this._elementType &&
(this._styleName === undefined || element.styleName === this._styleName) &&
(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;
}
|