mammoth-style
Version:
Convert Word documents (.docx files) to HTML (with style)
41 lines (34 loc) • 1.35 kB
JavaScript
exports.paragraph = paragraph;
exports.run = run;
exports.bold = new Matcher("bold");
exports.italic = new Matcher("italic");
exports.underline = new Matcher("underline");
exports.strikethrough = new Matcher("strikethrough");
exports.commentReference = new Matcher("commentReference");
function paragraph(options) {
return new Matcher("paragraph", options);
}
function run(options) {
return new Matcher("run", options);
}
function Matcher(elementType, options) {
options = options || {};
this._elementType = elementType;
this._styleId = options.styleId;
this._styleName = options.styleName;
if (options.list) {
this._listIndex = options.list.levelIndex;
this._listIsOrdered = options.list.isOrdered;
}
}
Matcher.prototype.matches = function(element) {
return element.type === this._elementType &&
(this._styleId === undefined || element.styleId === this._styleId) &&
(this._styleName === undefined || (element.styleName && element.styleName.toUpperCase() === this._styleName.toUpperCase())) &&
(this._listIndex === undefined || isList(element, this._listIndex, this._listIsOrdered));
};
function isList(element, levelIndex, isOrdered) {
return element.numbering &&
element.numbering.level == levelIndex &&
element.numbering.isOrdered == isOrdered;
}