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

feat(console): add rehypraw to display html for awesome akash templates #319

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions apps/deploy-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"react-simple-maps": "^3.0.0",
"react-use-websocket": "^3.0.0",
"rehype-highlight": "^6.0.0",
"rehype-raw": "^7.0.0",
"remark-gfm": "^3.0.1",
"sharp": "^0.30.3",
"stripe": "^10.14.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import React, { useEffect, useState } from "react";
import { Button, buttonVariants } from "@akashnetwork/ui/components";
import { ArrowRight, Cpu, Page, Rocket, Wrench, Linux } from "iconoir-react";
import { ArrowRight, Cpu, Linux,Page, Rocket, Wrench } from "iconoir-react";
import { NavArrowLeft } from "iconoir-react";
import { useAtom } from "jotai";
import Link from "next/link";
Expand Down
15 changes: 12 additions & 3 deletions apps/deploy-web/src/components/shared/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,37 @@
import "highlight.js/styles/vs2015.css";

import ReactMarkdown from "react-markdown";
import { PluggableList } from "react-markdown/lib/react-markdown";
import { useTheme } from "next-themes";
import rehypeHighlight from "rehype-highlight";
import rehypeRaw from "rehype-raw";
import remarkGfm from "remark-gfm";

import { cn } from "@src/utils/styleUtils";

type MarkdownProps = {
children?: React.ReactNode | string;
hasHtml?: boolean;
};

const Markdown: React.FunctionComponent<MarkdownProps> = ({ children }) => {
const Markdown: React.FunctionComponent<MarkdownProps> = ({ children, hasHtml }) => {
const { resolvedTheme } = useTheme();

const rehypePlugins: PluggableList = [[rehypeHighlight, { ignoreMissing: true }]];

if (hasHtml) {
rehypePlugins.push([rehypeRaw as any]);
}

return (
<ReactMarkdown
className={cn(
"markdownContainerRoot prose dark:prose-invert prose-code:before:hidden prose-code:after:hidden",
"markdownContainerRoot prose max-w-full dark:prose-invert prose-code:before:hidden prose-code:after:hidden",
resolvedTheme === "dark" ? "markdownContainer-dark" : "markdownContainer"
)}
linkTarget="_blank"
remarkPlugins={[remarkGfm]}
rehypePlugins={[[rehypeHighlight, { ignoreMissing: true }]]}
rehypePlugins={rehypePlugins}
>
{children as string}
</ReactMarkdown>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const TemplateDetail: React.FunctionComponent<Props> = ({ templateId, tem
{activeTab === "README" && (
<ViewPanel stickToBottom className="overflow-auto pb-12">
<div className="container pb-8 pt-4 sm:pt-8">
<Markdown>{_template?.readme}</Markdown>
<Markdown hasHtml={_template.id?.startsWith("akash-network-awesome-akash")}>{_template?.readme}</Markdown>
</div>
</ViewPanel>
)}
Expand Down
Loading
Loading