Hey is a decentralized and permissionless social media app built with Lens Protocol 馃尶
at main 31 lines 719 B view raw
1import type { Root } from "remark-parse/lib"; 2import type { Plugin } from "unified"; 3import { visitParents } from "unist-util-visit-parents"; 4 5const remarkLinkProtocolTransformer = (root: Root): Root => { 6 visitParents(root, "text", (textNode, parentNodes) => { 7 const linkNode = parentNodes[parentNodes.length - 1]; 8 9 if (linkNode?.type !== "link") { 10 return; 11 } 12 13 if (textNode.value !== linkNode.url) { 14 return; 15 } 16 17 const { url } = linkNode; 18 19 if (url.includes("//")) { 20 return; 21 } 22 23 textNode.value = `https://${url}`; 24 linkNode.url = `https://${url}`; 25 }); 26 27 return root; 28}; 29 30export const remarkLinkProtocol: Plugin<[], Root> = () => 31 remarkLinkProtocolTransformer;