Created
May 23, 2022 13:07
-
-
Save SebastianStehle/e9bf649b53f56c5d03f0e625055a800d to your computer and use it in GitHub Desktop.
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
const hotelsRegex = new RegExp(`${CONFIG.url}\\/api/content\\/${CONFIG.appName}\\/hotels/(?<id>[a-z0-9\\-]+)`); | |
export const Markdown = ({ markdown, references }) => { | |
return ( | |
<ReactMarkdown children={markdown} components={{ | |
a({ href, children }) { | |
const match = hotelsRegex.exec(href); | |
if (match && match.groups) { | |
const referenceId = match.groups.id; | |
const reference = references?.find(x => x.id === referenceId); | |
if (reference) { | |
return <EmbeddableHotel hotel={reference} />; | |
} | |
} | |
return <a href={href} target='_blank' rel='noopener noreferrer'>{children}</a>; | |
} | |
}} /> | |
) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment