aboutsummaryrefslogtreecommitdiff
path: root/lib/html-paths.js
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-08-28 19:55:24 +0100
committerMichael Williamson <mike@zwobble.org>2016-08-28 19:55:38 +0100
commitb1ae23f544c479d2b71347bbf67df7baac40d78f (patch)
tree383e694dae42ba544f690c3b0ab388a7931c0793 /lib/html-paths.js
parent7dba15069f9a606b9e248d7e4cd024ddaa6ac3e3 (diff)
parentc42714e5f4b643de27b106a084601e39b7e5d04c (diff)
Merge branch 'master' into image-errors
Conflicts: test/mammoth.tests.js
Diffstat (limited to 'lib/html-paths.js')
-rw-r--r--lib/html-paths.js31
1 files changed, 29 insertions, 2 deletions
diff --git a/lib/html-paths.js b/lib/html-paths.js
index 04bc655..5a00cd8 100644
--- a/lib/html-paths.js
+++ b/lib/html-paths.js
@@ -1,5 +1,7 @@
var _ = require("underscore");
+var html = require("./html");
+
exports.topLevelElement = topLevelElement;
exports.elements = elements;
exports.element = element;
@@ -9,15 +11,27 @@ function topLevelElement(tagName, attributes) {
}
function elements(elementStyles) {
- return elementStyles.map(function(elementStyle) {
+ return new HtmlPath(elementStyles.map(function(elementStyle) {
if (_.isString(elementStyle)) {
return element(elementStyle);
} else {
return elementStyle;
}
- });
+ }));
+}
+
+function HtmlPath(elements) {
+ this._elements = elements;
}
+HtmlPath.prototype.wrap = function wrap(children) {
+ var result = children();
+ for (var index = this._elements.length - 1; index >= 0; index--) {
+ result = this._elements[index].wrapNodes(result);
+ }
+ return result;
+};
+
function element(tagName, attributes, options) {
options = options || {};
return new Element(tagName, attributes, options);
@@ -44,4 +58,17 @@ Element.prototype.matchesElement = function(element) {
return this.tagNames[element.tagName] && _.isEqual(this.attributes || {}, element.attributes || {});
};
+Element.prototype.wrap = function wrap(generateNodes) {
+ return this.wrapNodes(generateNodes());
+};
+
+Element.prototype.wrapNodes = function wrapNodes(nodes) {
+ return [html.elementWithTag(this, nodes)];
+};
+
exports.empty = elements([]);
+exports.ignore = {
+ wrap: function() {
+ return [];
+ }
+};