Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding double check for links in markdown #449

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/components/current/Markdown.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import React, { ReactNode } from 'react';
import ReactMarkdown from 'react-markdown';

//======================================
export const Markdown = ({ children }: { children: string }) => {
// regex to match URLs in text that arent already formatted as links in markdown
const urlRegex = /(?<!\]\()https?:\/\/[^\s]+(?!\))/g;

// add markdown syntax to format links in text if they aren't already marked
const processedText = children.replace(urlRegex, (url) => `[${url}](${url})`);

return (
<ReactMarkdown
components={{
ul: (props) => <ul className="list-disc" {...props} />,
a: (props) => <a className="text-blue-400 underline" {...props} />,
a: (props) => (
<a className="testerino text-blue-400 underline" target="_blank" {...props} />
),
code: (props) => <code className="text-orange-300" {...props} />,
}}
>
{children}
{processedText}
</ReactMarkdown>
);
};