Skip to content

Commit

Permalink
replace react markdown with markdown component
Browse files Browse the repository at this point in the history
  • Loading branch information
sserrata committed Nov 20, 2024
1 parent 91d0dab commit b1e0a4d
Showing 1 changed file with 6 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@

import React from "react";

import CodeBlock from "@theme/CodeBlock";
import Markdown from "@theme/Markdown";
import SchemaTabs from "@theme/SchemaTabs";
import TabItem from "@theme/TabItem";
/* eslint-disable import/no-extraneous-dependencies*/
import clsx from "clsx";
import ReactMarkdown from "react-markdown";
import rehypeRaw from "rehype-raw";
import remarkGfm from "remark-gfm";

import { createDescription } from "../../markdown/createDescription";
import { getQualifierMessage, getSchemaName } from "../../markdown/schema";
import { guard, toString } from "../../markdown/utils";

Expand Down Expand Up @@ -97,46 +93,20 @@ function ParamsItem({ param, ...rest }: Props) {
<span className="openapi-schema__deprecated">deprecated</span>
));

const renderSchema = guard(getQualifierMessage(schema), (message) => (
<div>
<ReactMarkdown
children={createDescription(message)}
rehypePlugins={[rehypeRaw]}
/>
</div>
const renderQualifier = guard(getQualifierMessage(schema), (qualifier) => (
<Markdown>{qualifier}</Markdown>
));

const renderDescription = guard(description, (description) => (
<>
<ReactMarkdown
children={createDescription(description)}
components={{
pre: "div",
code({ node, inline, className, children, ...props }) {
const match = /language-(\w+)/.exec(className || "");
if (inline) return <code>{children}</code>;
return !inline && match ? (
<CodeBlock className={className}>{children}</CodeBlock>
) : (
<CodeBlock>{children}</CodeBlock>
);
},
}}
rehypePlugins={[rehypeRaw]}
/>
</>
<Markdown>{description}</Markdown>
));

const renderEnumDescriptions = guard(
getEnumDescriptionMarkdown(enumDescriptions),
(value) => {
return (
<div style={{ marginTop: ".5rem" }}>
<ReactMarkdown
rehypePlugins={[rehypeRaw]}
remarkPlugins={[remarkGfm]}
children={value}
/>
<Markdown>{value}</Markdown>
</div>
);
}
Expand Down Expand Up @@ -217,7 +187,7 @@ function ParamsItem({ param, ...rest }: Props) {
{renderSchemaRequired}
{renderDeprecated}
</span>
{renderSchema}
{renderQualifier}
{renderDescription}
{renderEnumDescriptions}
{renderDefaultValue()}
Expand Down

0 comments on commit b1e0a4d

Please sign in to comment.