Connect, collaborate, and grow with a community of TypeScript developers
Use Markdown compy (#530)
Sean Boult9ec2e9c813c9
diff --git a/apps/web/next.config.mjs b/apps/web/next.config.mjsindex 446ee000..65921ae0 100644--- a/apps/web/next.config.mjs+++ b/apps/web/next.config.mjs@@ -21,7 +21,7 @@ const nextConfig = {eslint: {ignoreDuringBuilds: true,},- transpilePackages: ['@repo/db', '@repo/auth', '@repo/monaco'],+ transpilePackages: ['@repo/db', '@repo/ui', '@repo/auth', '@repo/monaco'],images: {remotePatterns: [{diff --git a/apps/web/src/app/challenge/[id]/solutions/_components/solution-detail.tsx b/apps/web/src/app/challenge/[id]/solutions/_components/solution-detail.tsxindex dfc81562..45b28f14 100644--- a/apps/web/src/app/challenge/[id]/solutions/_components/solution-detail.tsx+++ b/apps/web/src/app/challenge/[id]/solutions/_components/solution-detail.tsx@@ -14,9 +14,9 @@ import {Tooltip,TooltipContent,TooltipTrigger,+ Markdown,} from '@repo/ui';import { Comments } from '~/app/challenge/_components/comments';-import { Markdown } from '~/components/ui/markdown';import type { ChallengeSolution } from '~/app/challenge/[id]/solutions/[solutionId]/page';import { ReportDialog } from '~/components/ReportDialog';diff --git a/apps/web/src/app/challenge/[id]/submissions/_components/overview.tsx b/apps/web/src/app/challenge/[id]/submissions/_components/overview.tsxindex 57adb4ef..0ab9cfee 100644--- a/apps/web/src/app/challenge/[id]/submissions/_components/overview.tsx+++ b/apps/web/src/app/challenge/[id]/submissions/_components/overview.tsx@@ -1,8 +1,15 @@import { useQuery } from '@tanstack/react-query';import { Copy, X } from '@repo/ui/icons';import Link from 'next/link';-import { Button, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, toast } from '@repo/ui';-import { Markdown } from '~/components/ui/markdown';+import {+ Markdown,+ Button,+ Tooltip,+ TooltipContent,+ TooltipProvider,+ TooltipTrigger,+ toast,+} from '@repo/ui';import { getBaseUrl } from '~/utils/getBaseUrl';import { getRelativeTime } from '~/utils/relativeTime';diff --git a/apps/web/src/app/challenge/_components/comments/comment-input.tsx b/apps/web/src/app/challenge/_components/comments/comment-input.tsxindex 683ccb3e..01959c55 100644--- a/apps/web/src/app/challenge/_components/comments/comment-input.tsx+++ b/apps/web/src/app/challenge/_components/comments/comment-input.tsx@@ -1,8 +1,7 @@import { Loader2 } from '@repo/ui/icons';import { useSession } from '@repo/auth/react';import { useEffect, useRef, useState, type RefObject } from 'react';-import { Button, Textarea, ToastAction, useToast } from '@repo/ui';-import { Markdown } from '~/components/ui/markdown';+import { Button, Textarea, Markdown, ToastAction, useToast } from '@repo/ui';interface Props {mode: 'create' | 'edit' | 'reply';diff --git a/apps/web/src/app/challenge/_components/comments/comment.tsx b/apps/web/src/app/challenge/_components/comments/comment.tsxindex 5c6fef22..46b000ee 100644--- a/apps/web/src/app/challenge/_components/comments/comment.tsx+++ b/apps/web/src/app/challenge/_components/comments/comment.tsx@@ -2,7 +2,7 @@import { useSession } from '@repo/auth/react';import { type CommentRoot } from '@repo/db/types';-import { Tooltip, TooltipContent, TooltipTrigger, UserBadge, toast } from '@repo/ui';+import { Tooltip, TooltipContent, Markdown, TooltipTrigger, UserBadge, toast } from '@repo/ui';import { ChevronDown, ChevronUp, Pencil, Reply, Share, Trash2 } from '@repo/ui/icons';import { useInfiniteQuery, useQueryClient } from '@tanstack/react-query';import clsx from 'clsx';@@ -10,7 +10,6 @@ import Link from 'next/link';import { useEffect, useRef, useState } from 'react';import { z } from 'zod';import { ReportDialog } from '~/components/ReportDialog';-import { Markdown } from '~/components/ui/markdown';import { getRelativeTime } from '~/utils/relativeTime';import { Vote } from '../vote';import { CommentInput } from './comment-input';diff --git a/apps/web/src/app/challenge/_components/comments/delete/index.tsx b/apps/web/src/app/challenge/_components/comments/delete/index.tsxindex 89bade47..f5acece1 100644--- a/apps/web/src/app/challenge/_components/comments/delete/index.tsx+++ b/apps/web/src/app/challenge/_components/comments/delete/index.tsx@@ -9,11 +9,11 @@ import {TooltipTrigger,TypographyLarge,TypographyP,+ Markdown,toast,} from '@repo/ui';import { useQueryClient } from '@tanstack/react-query';import { useState } from 'react';-import { Markdown } from '~/components/ui/markdown';import { getRelativeTime } from '~/utils/relativeTime';import { deleteComment } from '../comment.action';import { type PaginatedComments } from '../getCommentRouteData';diff --git a/apps/web/src/app/challenge/_components/description/index.tsx b/apps/web/src/app/challenge/_components/description/index.tsxindex 32a1dd7e..8a49c4fa 100644--- a/apps/web/src/app/challenge/_components/description/index.tsx+++ b/apps/web/src/app/challenge/_components/description/index.tsx@@ -14,6 +14,7 @@ import {TooltipTrigger,TypographyH3,UserBadge,+ Markdown,} from '@repo/ui';import { Bookmark as BookmarkIcon, Flag, Share } from '@repo/ui/icons';import { clsx } from 'clsx';@@ -22,7 +23,6 @@ import Link from 'next/link';import { useRef, useState } from 'react';import { type ChallengeRouteData } from '~/app/challenge/[id]/getChallengeRouteData';import { ReportDialog } from '~/components/ReportDialog';-import { Markdown } from '~/components/ui/markdown';import { getRelativeTime } from '~/utils/relativeTime';import { addOrRemoveBookmark } from '../bookmark.action';import { ShareForm } from '../share-form';diff --git a/apps/web/src/components/landing/feature-card.tsx b/apps/web/src/components/landing/feature-card.tsxindex e338d174..f4b21baf 100644--- a/apps/web/src/components/landing/feature-card.tsx+++ b/apps/web/src/components/landing/feature-card.tsx@@ -1,7 +1,7 @@'use client';import type { Challenge, Difficulty } from '@repo/db/types';-import { Button } from '@repo/ui';+import { Button, Markdown } from '@repo/ui';import clsx from 'clsx';import {motion,@@ -18,7 +18,6 @@ import { useInView } from 'react-intersection-observer';import { z } from 'zod';import { TrackChallenge } from '~/app/tracks/_components/track-challenge-card';import { useIsMobile } from '~/utils/useIsMobile';-import { Markdown } from '../ui/markdown';import { Steps } from '../wizard/Steps';type WrapperStyle = MotionStyle & {diff --git a/apps/web/src/components/ui/markdown.tsx b/apps/web/src/components/ui/markdown.tsxdeleted file mode 100644index 8740f363..00000000--- a/apps/web/src/components/ui/markdown.tsx+++ /dev/null@@ -1,89 +0,0 @@-'use client';--import ReactMarkdown from 'react-markdown';-import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';-import remarkGfm from 'remark-gfm';-import { vs, vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism';-import clsx from 'clsx';-import { visit, SKIP, type BuildVisitor } from 'unist-util-visit';-import type { Transformer } from 'unified';-import { useTheme } from 'next-themes';--const HTML_COMMENT_REGEX = new RegExp('<!--([\\s\\S]*?)-->', 'g');--/**- * Remove HTML comments from Markdown- */-function removeHtmlComments(): Transformer {- return (tree) => {- // TODO: PRs are welcomed to fix the any type- // eslint-disable-next-line- const handler: BuildVisitor<any> = (node, index, parent) => {- const isComment = node.value.match(HTML_COMMENT_REGEX);-- if (isComment) {- // remove node- parent.children.splice(index, 1);- // Do not traverse `node`, continue at the node *now* at `index`. http://unifiedjs.com/learn/recipe/remove-node/- return [SKIP, index];- }- };-- visit(tree, 'html', handler);-- // TODO: is this needed- visit(tree, 'jsx', handler);- };-}--export function Markdown({ children, className }: { children: string; className?: string }) {- const { theme } = useTheme();- const syntaxHighlighterTheme = theme === 'light' ? vs : vscDarkPlus;-- return (- <ReactMarkdown- className={className}- components={{- a: ({ className, ...props }) => (- <a className={clsx(className, 'text-blue-500')} {...props} />- ),- ul: ({ className, ...props }) => (- <ul className={clsx(className, 'list-disc ps-10')} {...props} />- ),- h1: ({ className, ...props }) => (- <h1 className={clsx(className, 'mb-2 pb-2 text-3xl font-bold')} {...props} />- ),- h2: ({ className, ...props }) => (- <h2 className={clsx(className, 'mb-2 pb-2 text-2xl font-bold')} {...props} />- ),- h3: ({ className, ...props }) => (- <h3 className={clsx(className, 'mb-2 pb-2 text-xl font-bold')} {...props} />- ),- p: ({ className, ...props }) => (- <p className={clsx(className, 'mb-4 last-of-type:mb-1.5')} {...props} />- ),- code({ inline, className, children, style: _, ...props }) {- const match = /language-(\w+)/.exec(className || '');- return !inline && match ? (- <SyntaxHighlighter- PreTag="section" // parent tag- className={clsx(className, 'rounded-xl dark:rounded-md')}- language={match[1]}- style={syntaxHighlighterTheme} // theme- {...props}- >- {String(children).replace(/\n$/, '')}- </SyntaxHighlighter>- ) : (- <code className="rounded-md bg-neutral-200 p-1 font-mono dark:bg-black">- {children}- </code>- );- },- }}- remarkPlugins={[removeHtmlComments, remarkGfm]}- >- {children}- </ReactMarkdown>- );-}diff --git a/apps/web/src/components/wizard/DescriptionEditor.tsx b/apps/web/src/components/wizard/DescriptionEditor.tsxindex 295a1108..8d89457a 100644--- a/apps/web/src/components/wizard/DescriptionEditor.tsx+++ b/apps/web/src/components/wizard/DescriptionEditor.tsx@@ -1,8 +1,7 @@'use client';import { useWatch } from 'react-hook-form';-import { FormField, FormItem, FormMessage, TypographyH3 } from '@repo/ui';-import { Markdown } from '../ui/markdown';+import { Markdown, FormField, FormItem, FormMessage, TypographyH3 } from '@repo/ui';import { RichMarkdownEditor } from '../ui/rich-markdown-editor';import { type WizardForm } from '.';