Skip to content

Commit 77843f2

Browse files
committed
Allow ignoring elements
1 parent d75642e commit 77843f2

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

make-tree.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ function makeHeadingId(text) {
6060
function makeTreeData(elements) {
6161
var ids = {};
6262
var map = [].map;
63-
63+
elements = elements.filter(function(element) {
64+
// for testing
65+
if (element.attributes) {
66+
return !element.attributes['data-skip'];
67+
}
68+
return true;
69+
});
6470
return map.call(elements, function(element) {
6571
var text = element.textContent;
6672
var id = element.id || makeHeadingId(text);

test/make-tree-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,16 @@ describe("makeTree", function() {
5656
{ id: "writing-modules", level: 2, text: "Writing Modules", children: [] }
5757
]);
5858
});
59+
60+
it("allows ignoring elements with data-skip attribute", function() {
61+
var elements = [
62+
{ tagName: "h2", textContent: "new MyType", attributes: {} },
63+
{ tagName: "h3", textContent: "Parameters", attributes: { 'data-skip': {} } },
64+
{ tagName: "h2", textContent: "Configure", attributes: {} }
65+
];
66+
assert.deepEqual(makeTree(elements), [
67+
{id: "new-mytype", level: 2, text: "new MyType", children: []},
68+
{ id: "configure", level: 2, text: "Configure", children: [] }
69+
]);
70+
});
5971
});

0 commit comments

Comments
 (0)