Last active
December 9, 2020 00:46
-
-
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
This file contains hidden or 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
.Figure-content .Link { | |
color: var(--linkColor); | |
} | |
.Figure-content .Link:hover { | |
color: var(--linkHoverColor); | |
} |
This file contains hidden or 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
// 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