Skip to content

Instantly share code, notes, and snippets.

@ricealexander
Last active December 9, 2020 00:46
Show Gist options
  • Save ricealexander/bfd987089d2f850cb5d9710739f183d0 to your computer and use it in GitHub Desktop.
Save ricealexander/bfd987089d2f850cb5d9710739f183d0 to your computer and use it in GitHub Desktop.
Grove doesn't support links in image captions. This workaround converts Markdown-style links into HTML links
.Figure-content .Link {
color: var(--linkColor);
}
.Figure-content .Link:hover {
color: var(--linkHoverColor);
}
// Markdown Link Regex
// \[
// ([^\]]+)
// \]
// \(
// ([^\)]+)
// \)
const linkPattern = /\[([^\]]+)\]\(([^\)]+)\)/g
function parseMarkdownLinks (content) {
const formattedMarkup = content.replace(linkPattern, (...args) => {
const [, linkText, url] = args
return `<a class="Link" href="${url}">${linkText}</a>`
})
return formattedMarkup
}
function linkSupportForCaptions () {
const imageCaptions = document.querySelectorAll('.Figure-content');
for (const caption of imageCaptions) {
caption.innerHTML = parseMarkdownLinks(caption.innerHTML)
}
}
module.exports = () => {
linkSupportForCaptions()
window.onNavigate.push(linkSupportForCaptions)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment