From d18040dca1c54e21a8a8a17bdb851701dff1a156 Mon Sep 17 00:00:00 2001 From: ecwu Date: Fri, 7 Feb 2025 21:32:14 +0000 Subject: [PATCH] Add @tailwindcss/typography plugin and update MessageBubble component for improved Markdown rendering --- package.json | 1 + pnpm-lock.yaml | 40 ++++++++++++++ src/components/MessageBubble.tsx | 91 +++++++++----------------------- tailwind.config.cjs | 9 +++- 4 files changed, 74 insertions(+), 67 deletions(-) diff --git a/package.json b/package.json index bc83a7c..7eb9e13 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "@radix-ui/react-toggle": "^1.1.1", "@radix-ui/react-toggle-group": "^1.1.1", "@radix-ui/react-tooltip": "^1.1.6", + "@tailwindcss/typography": "^0.5.16", "@types/react": "^18.0.0", "@types/react-dom": "^18.0.0", "@types/ungap__structured-clone": "^1.2.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4faa42e..4b4fead 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -95,6 +95,9 @@ importers: '@radix-ui/react-tooltip': specifier: ^1.1.6 version: 1.1.8(@types/react-dom@18.3.5(@types/react@18.3.18))(@types/react@18.3.18)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@tailwindcss/typography': + specifier: ^0.5.16 + version: 0.5.16(tailwindcss@3.4.17) '@types/react': specifier: ^18.0.0 version: 18.3.18 @@ -1697,6 +1700,11 @@ packages: '@surma/rollup-plugin-off-main-thread@2.2.3': resolution: {integrity: sha512-lR8q/9W7hZpMWweNiAKU7NQerBnzQQLvi8qnTDU/fxItPhtZVMbPV3lbCwjhIlNBe9Bbr5V+KHshvWmVSG9cxQ==} + '@tailwindcss/typography@0.5.16': + resolution: {integrity: sha512-0wDLwCVF5V3x3b1SGXPCDcdsbDHMBe+lkFzBRaHeLvNi+nrrnZ1lA18u+OTWO8iSWU2GxUOCvlXtDuqftc1oiA==} + peerDependencies: + tailwindcss: '>=3.0.0 || insiders || >=4.0.0-alpha.20 || >=4.0.0-beta.1' + '@types/babel__core@7.20.5': resolution: {integrity: sha512-qoQprZvz5wQFJwMDqeseRXWv3rqMvhgpbXFfVyWhbx9X47POIA6i/+dXefEmZKoAgOaTdaIgNSMqMIU61yRyzA==} @@ -2620,9 +2628,18 @@ packages: lines-and-columns@1.2.4: resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==} + lodash.castarray@4.4.0: + resolution: {integrity: sha512-aVx8ztPv7/2ULbArGJ2Y42bG1mEQ5mGjpdvrbJcJFU3TbYybe+QlLS4pst9zV52ymy2in1KpFPiZnAOATxD4+Q==} + lodash.debounce@4.0.8: resolution: {integrity: sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==} + lodash.isplainobject@4.0.6: + resolution: {integrity: sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==} + + lodash.merge@4.6.2: + resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==} + lodash.sortby@4.7.0: resolution: {integrity: sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA==} @@ -2902,6 +2919,10 @@ packages: peerDependencies: postcss: ^8.2.14 + postcss-selector-parser@6.0.10: + resolution: {integrity: sha512-IQ7TZdoaqbT+LCpShg46jnZVlhWD2w6iQYAcYXfHARZ7X1t/UGhhceQDs5X0cGqKvYlHNOuv7Oa1xmb0oQuA3w==} + engines: {node: '>=4'} + postcss-selector-parser@6.1.2: resolution: {integrity: sha512-Q8qQfPiZ+THO/3ZrOrO0cJJKfpYCagtMUkXbnEfmgUjwXg6z/WBeOyS9APBBPCTSiDV+s4SwQGu8yFsiMRIudg==} engines: {node: '>=4'} @@ -5205,6 +5226,14 @@ snapshots: magic-string: 0.25.9 string.prototype.matchall: 4.0.12 + '@tailwindcss/typography@0.5.16(tailwindcss@3.4.17)': + dependencies: + lodash.castarray: 4.4.0 + lodash.isplainobject: 4.0.6 + lodash.merge: 4.6.2 + postcss-selector-parser: 6.0.10 + tailwindcss: 3.4.17 + '@types/babel__core@7.20.5': dependencies: '@babel/parser': 7.26.7 @@ -6227,8 +6256,14 @@ snapshots: lines-and-columns@1.2.4: {} + lodash.castarray@4.4.0: {} + lodash.debounce@4.0.8: {} + lodash.isplainobject@4.0.6: {} + + lodash.merge@4.6.2: {} + lodash.sortby@4.7.0: {} lodash@4.17.21: {} @@ -6631,6 +6666,11 @@ snapshots: postcss: 8.5.1 postcss-selector-parser: 6.1.2 + postcss-selector-parser@6.0.10: + dependencies: + cssesc: 3.0.0 + util-deprecate: 1.0.2 + postcss-selector-parser@6.1.2: dependencies: cssesc: 3.0.0 diff --git a/src/components/MessageBubble.tsx b/src/components/MessageBubble.tsx index 59edfb8..591c4f7 100644 --- a/src/components/MessageBubble.tsx +++ b/src/components/MessageBubble.tsx @@ -305,7 +305,7 @@ export default function Message(props: { messageIndex: number }) { )} {chat.role === "assistant" ? ( -
+
{chat.reasoning_content ? ( @@ -336,74 +336,33 @@ export default function Message(props: { messageIndex: number }) { ) : chat.tool_calls ? ( ) : renderMarkdown ? ( -
+
( - {children} - ), - em: ({ children }) => ( - {children} - ), - code: ({ children }) => ( - - {children} - - ), - pre: ({ children }) => ( -
-                        {children}
-                      
- ), - a: ({ href, children }) => ( - - {children} - - ), - ol: ({ children }) => ( -
    - {children} -
- ), - ul: ({ children }) => ( -
    {children}
- ), - li: ({ children }) =>
  • {children}
  • , - p: ({ children, node }: any) => { - if (node?.parent?.type === "listItem") { - return <>{children}; - } - return

    {children}

    ; - }, - h1: ({ children }) => ( -

    - {children} -

    - ), - h2: ({ children }) => ( -

    - {children} -

    - ), - h3: ({ children }) => ( -

    - {children} -

    - ), - blockquote: ({ children }) => ( -
    - {children} -
    - ), - }} + disallowedElements={[ + "script", + "iframe", + "object", + "embed", + "hr", + ]} + // allowElement={(element) => { + // return [ + // "p", + // "em", + // "strong", + // "del", + // "code", + // "inlineCode", + // "blockquote", + // "ul", + // "ol", + // "li", + // "pre", + // ].includes(element.tagName); + // }} + className={"prose"} > {getMessageText(chat)}
    diff --git a/tailwind.config.cjs b/tailwind.config.cjs index f4af1ca..35cf789 100644 --- a/tailwind.config.cjs +++ b/tailwind.config.cjs @@ -4,6 +4,13 @@ module.exports = { content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"], theme: { extend: { + typography: (theme) => ({ + DEFAULT: { + css: { + + }, + }, + }), borderRadius: { lg: 'var(--radius)', md: 'calc(var(--radius) - 2px)', @@ -85,5 +92,5 @@ module.exports = { } } }, - plugins: [require("tailwindcss-animate")], + plugins: [require("tailwindcss-animate"), require("@tailwindcss/typography")], };