diff --git a/core/src/components/decorate-internal-refs/decorate-internal-refs.tsx b/core/src/components/decorate-internal-refs/decorate-internal-refs.tsx index 0796740b..3a8f83d7 100644 --- a/core/src/components/decorate-internal-refs/decorate-internal-refs.tsx +++ b/core/src/components/decorate-internal-refs/decorate-internal-refs.tsx @@ -109,7 +109,14 @@ export class DecorateInternalRefs { if (this.akomaNtosoElement) { const href: string = tippy.reference.getAttribute('href') || ''; let html: string | null = ''; - const provision: HTMLElement | null = this.akomaNtosoElement.querySelector(href); + let provision: HTMLElement | null = null; + + try { + provision = this.akomaNtosoElement.querySelector(href); + } catch (e) { + // ignore query selector errors + console.log(e); + } if (provision) { html = provision.outerHTML; diff --git a/core/src/components/decorate-terms/decorate-terms.tsx b/core/src/components/decorate-terms/decorate-terms.tsx index a88da88d..41dd4425 100644 --- a/core/src/components/decorate-terms/decorate-terms.tsx +++ b/core/src/components/decorate-terms/decorate-terms.tsx @@ -129,7 +129,12 @@ export class DecorateTerms { const term = reference.getAttribute('data-refersto'); // find where the term is defined if (this.akomaNtosoElement) { - return this.akomaNtosoElement.querySelector(`[data-defines="${term}"]`); + try { + return this.akomaNtosoElement.querySelector(`[data-defines="${term}"]`); + } catch (e) { + // ignore query selector errors + console.log(e); + } } return null; } diff --git a/core/src/components/gutter/layout.ts b/core/src/components/gutter/layout.ts index c9fb9590..2be8cfce 100644 --- a/core/src/components/gutter/layout.ts +++ b/core/src/components/gutter/layout.ts @@ -143,7 +143,12 @@ export class GutterLayout { if (item.anchor instanceof HTMLElement) { return this.root.contains(item.anchor) ? item.anchor : null; } else { - return this.root.querySelector(item.anchor); + try { + return this.root.querySelector(item.anchor); + } catch (e) { + // ignore query selector errors + console.log(e); + } } } return null; diff --git a/core/src/utils/linking.ts b/core/src/utils/linking.ts index f9d45877..06afb4e6 100644 --- a/core/src/utils/linking.ts +++ b/core/src/utils/linking.ts @@ -55,9 +55,15 @@ export class AkomaNtosoTarget { findElement(): HTMLElement | null { if (this.selector) { - return this.selector instanceof HTMLElement - ? this.selector - : this.component.ownerDocument.querySelector(this.selector); + try { + return this.selector instanceof HTMLElement + ? this.selector + : this.component.ownerDocument.querySelector(this.selector); + } catch (e) { + // fail on query selector errors + console.log(e); + return null; + } } // try the nearest ancestor