Skip to content

Commit

Permalink
search for nested tags in find-tags-by-name
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed Jul 23, 2022
1 parent ed1566b commit cb8151f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion find-tags-by-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ const findTagByName = require("./find-tag-by-name.js");
function findTagsByName(xml, tagName, options) {
const tags = [];
const debug = (options && options.debug) || false;
const nested = options && typeof options.nested === "boolean" ? options.nested : true;
let startIndex = (options && options.startIndex) || 0;
let tag;
while ((tag = findTagByName(xml, tagName, { debug, startIndex }))) {
startIndex = tag.end;
if (nested) {
startIndex = tag.start + 1 + tagName.length;
} else {
startIndex = tag.end;
}
tags.push(tag);
}
if (debug) console.log("findTagsByName found", tags.length, "tags");
Expand Down

0 comments on commit cb8151f

Please sign in to comment.