core: fix Cannot read properties of undefined (reading 'startsWith') error on export

This commit is contained in:
Abdullah Atta
2024-05-16 09:06:43 +05:00
committed by Abdullah Atta
parent 62d677f9ad
commit 1e6f6ab477
2 changed files with 6 additions and 3 deletions

View File

@@ -184,7 +184,7 @@ export class Tiptap {
this.data = new HTMLRewriter({
ontag: (name, attr) => {
const href = attr[ATTRIBUTES.href];
if (name === "a" && href.startsWith("nn://")) {
if (name === "a" && href && href.startsWith("nn://")) {
const link = resolve(href);
if (!link) return;
attr[ATTRIBUTES.href] = link;
@@ -244,7 +244,10 @@ export class Tiptap {
if (types.includes("internalLinks")) {
result.internalLinks.push(
...findAll(
(e) => e.tagName === "a" && e.attribs.href.startsWith("nn://"),
(e) =>
e.tagName === "a" &&
!!e.attribs.href &&
e.attribs.href.startsWith("nn://"),
document.childNodes
)
.map((e) => parseInternalLink(e.attribs.href))

View File

@@ -66,7 +66,7 @@ export function parseInternalLink(link: string): InternalLink | undefined {
}
export function isInternalLink(link: string) {
return link.startsWith("nn://");
return link && link.startsWith("nn://");
}
function isValidInternalType(type: string): type is InternalLinkType {