Skip to content

Commit

Permalink
feat: Add support for mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
andymac4182 committed May 5, 2023
1 parent c01ae97 commit f17dd84
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
17 changes: 17 additions & 0 deletions packages/lib/src/AdfProcessing.ts
Expand Up @@ -697,6 +697,23 @@ function processWikilinkToActualLink(
}
return node;
}
if (
typeof node.marks[0].attrs["href"] === "string" &&
node.marks[0].attrs["href"].startsWith("mention:")
) {
console.log({ node });
const mentionUrl = new URL(node.marks[0].attrs["href"]);

node = {
type: "mention",
attrs: {
id: mentionUrl.pathname,
text: node.text,
},
};

return node;
}
}
return;
},
Expand Down
4 changes: 3 additions & 1 deletion packages/lib/src/MarkdownTransformer/wikilinks.ts
Expand Up @@ -54,7 +54,9 @@ export function wikilinks(state: StateInline): boolean {
state.posMax = wikiLinkEnd;
}

const href = `wikilinks:${linkToPage}${hashFragment ?? ""}`;
const href = linkToPage.startsWith("mention:")
? linkToPage
: `wikilinks:${linkToPage}${hashFragment ?? ""}`;

let token = state.push("link_open", "a", 1);
token.attrs = [["href", href]];
Expand Down
5 changes: 4 additions & 1 deletion packages/lib/src/MdToADF.ts
Expand Up @@ -43,7 +43,10 @@ function processADF(adf: JSONDocNode): JSONDocNode {
node.marks[0].attrs["href"] === "" ||
(!isSafeUrl(node.marks[0].attrs["href"]) &&
!(node.marks[0].attrs["href"] as string).startsWith(
"wikilink"
"wikilinks:"
) &&
!(node.marks[0].attrs["href"] as string).startsWith(
"mention:"
))
) {
node.marks[0].attrs["href"] = "#";
Expand Down

0 comments on commit f17dd84

Please sign in to comment.