Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rendering external links to new tabs
- Loading branch information
Showing
4 changed files
with
34 additions
and
17 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import ReactMarkdown from "react-markdown"; | ||
import remarkGfm from "remark-gfm"; | ||
|
||
// Define a type for the renderer functions | ||
type RendererFunction = (props: any) => JSX.Element; | ||
|
||
// Define the renderers with basic types | ||
const renderers: { [nodeType: string]: RendererFunction } = { | ||
a: ({ href, children }) => { | ||
return href.startsWith("https://") ? ( | ||
<a href={href} target="_blank" rel="noopener noreferrer"> | ||
{children} | ||
</a> | ||
) : ( | ||
<a href={href}>{children}</a> | ||
); | ||
}, | ||
}; | ||
|
||
type MarkdownContentProps = { | ||
content: string; | ||
}; | ||
|
||
const MarkdownContent: React.FC<MarkdownContentProps> = ({ content }) => ( | ||
<ReactMarkdown components={renderers as any} remarkPlugins={[remarkGfm]}> | ||
{content} | ||
</ReactMarkdown> | ||
); | ||
|
||
export default MarkdownContent; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,6 @@ | ||
import { type ClassValue, clsx } from "clsx"; | ||
import { twMerge } from "tailwind-merge"; | ||
|
||
import { remark } from "remark"; | ||
import html from "remark-html"; | ||
|
||
export function cn(...inputs: ClassValue[]) { | ||
return twMerge(clsx(inputs)); | ||
} | ||
|
||
export async function markdownToHtml(markdown: string) { | ||
const result = await remark() | ||
.use(html, { sanitize: false }) | ||
.process(markdown); | ||
return result.toString(); | ||
} |