Last active
November 18, 2023 21:44
-
-
Save jrobinsonc/7d945d208e512c977626a6ac9c4b4fbf to your computer and use it in GitHub Desktop.
Markdown Link Parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Link { | |
text: string; | |
url: string; | |
} | |
function parseMarkdownLinks(markdownText: string): Link[] { | |
const linkRegex: RegExp = /\[([^\]]+)\]\(([^\)]+)\)/g; | |
const links: Link[] = []; | |
let match: RegExpExecArray | null; | |
while ((match = linkRegex.exec(markdownText)) !== null) { | |
links.push({ text: match[1], url: match[2] }); | |
} | |
return links; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment