Skip to content

Instantly share code, notes, and snippets.

@SebastianStehle
Created May 23, 2022 13:07
Show Gist options
  • Save SebastianStehle/e9bf649b53f56c5d03f0e625055a800d to your computer and use it in GitHub Desktop.
Save SebastianStehle/e9bf649b53f56c5d03f0e625055a800d to your computer and use it in GitHub Desktop.
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