Skip to content

Commit

Permalink
Fix some exceptions that may happen from an incorrect use of span ids
Browse files Browse the repository at this point in the history
  • Loading branch information
davivcu committed Nov 30, 2023
1 parent f903a00 commit 1854081
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/app/utils/xml-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,22 @@ export function getContentBetweenElementAndId(fromElement: XMLElement, toXMLID:
const cleanID = toXMLID.replace('#','');
let found = false;
// text after the milestone but still inside the parent element
let foundText = fromElement.nextSibling.textContent;
let foundText = (fromElement.nextSibling !== null) ? fromElement.nextSibling.textContent : '';
// the milestone is always inside another element?
// otherwise const foundElements = [fromElement.nextSibling];
let next = (fromElement.nextElementSibling !== null) ?
fromElement.nextElementSibling as XMLElement :
fromElement.parentElement.nextElementSibling as XMLElement;

// creating a fake element for partial text included from milestone on
const nextEdited = fromElement.parentElement.nextElementSibling.cloneNode(true);
nextEdited.textContent = foundText;
const foundElements = [nextEdited];
let foundElements = [];
if (fromElement.parentElement.nextElementSibling !== null) {
const nextEdited = fromElement.parentElement.nextElementSibling.cloneNode(true);
nextEdited.textContent = foundText;
foundElements.push(nextEdited);
}

let maxExec = 1000;
let maxExec = 50;

while(!found && next !== null && maxExec !== 0) {
foundElements.push(next);
Expand All @@ -143,7 +146,12 @@ export function getContentBetweenElementAndId(fromElement: XMLElement, toXMLID:
} else {
maxExec--;
if (next.nextElementSibling === null) {
next = next.parentElement.nextElementSibling as XMLElement;
if (next.parentElement !== null) {
next = next.parentElement.nextElementSibling as XMLElement;
maxExec--;
} else {
next = null;
}
} else {
next = next.nextElementSibling as XMLElement;
}
Expand Down

0 comments on commit 1854081

Please sign in to comment.