import { useState, useEffect } from 'react'; import { httpClient } from '@/app/infra/http/HttpClient'; import { useTranslation } from 'react-i18next'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import rehypeRaw from 'rehype-raw'; import rehypeSanitize from 'rehype-sanitize'; import rehypeHighlight from 'rehype-highlight'; import rehypeSlug from 'rehype-slug'; import rehypeAutolinkHeadings from 'rehype-autolink-headings'; import { getAPILanguageCode } from '@/i18n/I18nProvider'; import '@/styles/github-markdown.css'; export default function PluginReadme({ pluginAuthor, pluginName, }: { pluginAuthor: string; pluginName: string; }) { const { t } = useTranslation(); const [readme, setReadme] = useState(''); const [isLoadingReadme, setIsLoadingReadme] = useState(false); const language = getAPILanguageCode(); useEffect(() => { // Fetch plugin README setIsLoadingReadme(true); httpClient .getPluginReadme(pluginAuthor, pluginName, language) .then((res) => { setReadme(res.readme); }) .catch(() => { setReadme(''); }) .finally(() => { setIsLoadingReadme(false); }); }, [pluginAuthor, pluginName]); return (
{isLoadingReadme ? (
{t('plugins.loadingReadme')}
) : readme ? (
    {children}
, ol: ({ children }) => (
    {children}
), li: ({ children }) =>
  • {children}
  • , img: ({ src, alt, ...props }) => { let imageSrc = src || ''; if (typeof imageSrc !== 'string') { return ( {alt ); } if ( imageSrc && !imageSrc.startsWith('http://') && !imageSrc.startsWith('https://') && !imageSrc.startsWith('data:') ) { imageSrc = imageSrc.replace(/^(\.\/|\/)+/, ''); if (!imageSrc.startsWith('assets/')) { imageSrc = `assets/${imageSrc}`; } const assetPath = imageSrc.replace(/^assets\//, ''); imageSrc = httpClient.getPluginAssetURL( pluginAuthor, pluginName, assetPath, ); } return ( {alt ); }, }} > {readme}
    ) : (
    {t('plugins.noReadme')}
    )}
    ); }