Skip to content

Commit

Permalink
Merge pull request microsoft#250 from microsoft/package-upgrade
Browse files Browse the repository at this point in the history
Remove code-block component and add fence
  • Loading branch information
davidxw authored Nov 2, 2023
2 parents d801718 + 7c14529 commit bb05c0f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 82 deletions.
80 changes: 0 additions & 80 deletions src/components/chat/code-block.tsx

This file was deleted.

31 changes: 31 additions & 0 deletions src/components/markdown/code-block.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { FC, memo } from "react";
import { Prism } from "react-syntax-highlighter";
import { atomDark } from "react-syntax-highlighter/dist/esm/styles/prism";

export const fence = {
render: "CodeBlock",
attributes: {
language: {
type: String,
},
value: {
type: String,
},
},
};

interface Props {
language: string;
children: string;
}

export const CodeBlock: FC<Props> = memo(({ language, children }) => {
console.log(language);
return (
<Prism language={language} style={atomDark} PreTag="pre" showLineNumbers>
{children}
</Prism>
);
});

CodeBlock.displayName = "CodeBlock";
4 changes: 3 additions & 1 deletion src/components/markdown/config.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { citation } from "@/features/chat/chat-ui/markdown/citation";
import { Config } from "@markdoc/markdoc";
import { fence } from "./code-block";
import { paragraph } from "./paragraph";

export const citationConfig: Config = {
nodes: {
paragraph: paragraph,
paragraph,
fence,
},
tags: {
citation,
Expand Down
3 changes: 2 additions & 1 deletion src/components/markdown/markdown.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Markdoc from "@markdoc/markdoc";
import React, { FC } from "react";
import { Citation } from "../../features/chat/chat-ui/markdown/citation";
import { CodeBlock } from "./code-block";
import { citationConfig } from "./config";
import { Paragraph } from "./paragraph";

Expand All @@ -16,6 +17,6 @@ export const Markdown: FC<Props> = (props) => {
});

return Markdoc.renderers.react(content, React, {
components: { Citation, Paragraph },
components: { Citation, Paragraph, CodeBlock },
});
};

0 comments on commit bb05c0f

Please sign in to comment.