Skip to content

Commit

Permalink
support mdx
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelglass committed Mar 1, 2024
1 parent 7805040 commit 3fb54ef
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
3 changes: 3 additions & 0 deletions packages/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
},
"type": "module",
"dependencies": {
"@mdx-js/react": "^3.0.1",
"@mdx-js/rollup": "^3.0.1",
"@nlxai/chat-core": "*",
"@nlxai/chat-react": "*",
"@nlxai/chat-widget": "*",
Expand All @@ -26,6 +28,7 @@
"devDependencies": {
"@babel/core": "^7.23.3",
"@tailwindcss/typography": "^0.5.10",
"@types/mdx": "^2.0.11",
"@types/ramda": "0.29.1",
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
Expand Down
30 changes: 18 additions & 12 deletions packages/website/src/components/PageContent.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { type FC, type ReactNode, useState } from "react";
import { MDXProvider } from "@mdx-js/react";
import Markdown from "react-markdown";
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
import { CheckIcon, ContentCopyIcon } from "./Icons";
import remarkGfm from "remark-gfm";

const CopyToClipboardButton: FC<{ text: string; className?: string }> = ({
text,
Expand Down Expand Up @@ -41,18 +41,21 @@ export const Prose: FC<{ children: ReactNode; className?: string }> = ({
</div>
);

export const PageContent: FC<{ md: string }> = ({ md }) => (
export const PageContent: FC<{ md: string; children?: React.ReactNode }> = ({
md,
children,
}) => (
<Prose>
<Markdown
remarkPlugins={[remarkGfm]}
<MDXProvider
components={{
pre(props) {
return (
<pre className="relative group !font-mono">{props.children}</pre>
);
pre({ children }: React.HTMLAttributes<HTMLPreElement>) {
return <pre className="relative group !font-mono">{children}</pre>;
},
code(props) {
const { children, className, node, ...rest } = props;
code({
children,
className,
...rest
}: React.HTMLAttributes<HTMLElement>) {
const match = /language-(\w+)/.exec(className || "");
const lines = String(children).replace(/\n$/, "");
return (
Expand Down Expand Up @@ -80,7 +83,10 @@ export const PageContent: FC<{ md: string }> = ({ md }) => (
},
}}
>
{md}
</Markdown>
<Markdown>{md}</Markdown>
<main>{children}</main>
</MDXProvider>
</Prose>
);

export default PageContent;
4 changes: 2 additions & 2 deletions packages/website/src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { flatten } from "ramda";
import { Routes, Route } from "react-router-dom";
import { NextPrevPage } from "./components/NextPrevPage";
// 1
import { GettingStarted } from "./content/01-01-getting-started";
import { Installation } from "./content/01-02-installation";
import GettingStarted from "./content/01-01-getting-started.mdx";
import Installation from "./content/01-02-installation.mdx";
// 2
import { WebWidgetSetup } from "./content/02-01-web-widget-setup";
import { WebWidgetTheming } from "./content/02-02-web-widget-theming";
Expand Down
7 changes: 6 additions & 1 deletion packages/website/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import mdx from "@mdx-js/rollup";
import remarkGfm from "remark-gfm";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
plugins: [
{ enforce: "pre", ...mdx({ remarkPlugins: [remarkGfm] }) },
react({ include: /\.(mdx|js|jsx|ts|tsx)$/ }),
],
define: {},
server: {
port: 3010,
Expand Down

0 comments on commit 3fb54ef

Please sign in to comment.