import { Tag } from "@markdoc/markdoc";

function checkIfExternal(attributes) {
  const href = attributes.href;
  if (
    href.includes(
      "https://urbit.org" ||
        href.startsWith("/") ||
        href.startsWith("#") ||
        href.startsWith("?")
    )
  ) {
    return "_self";
  } else {
    return "_blank";
  }
}

export const link = {
  render: "a",
  children: ["strong", "em", "s", "code", "text", "tag"],
  attributes: {
    href: { type: String, required: true },
    title: { type: String },
    target: { type: String },
  },
  transform(node, config) {
    const attributes = node.transformAttributes(config);
    const children = node.transformChildren(config);

    const target = checkIfExternal(attributes);

    return new Tag(`a`, { ...attributes, target }, children);
  },
};

@@ -130,23 +130,16 @@
 ncludes(
-%0A      
 %22https:/
@@ -149,24 +149,21 @@
 bit.org%22
+)
  %7C%7C%0A
-    
     href
@@ -178,36 +178,32 @@
 ith(%22/%22) %7C%7C%0A    
- 
-   
 href.startsWith(
@@ -210,20 +210,16 @@
 %22#%22) %7C%7C%0A
-    
     href
@@ -239,14 +239,8 @@
 ?%22)%0A
-    )%0A
   ) 

fix href check