diff --git a/src/components/MarkdownRender/Pre.jsx b/src/components/MarkdownRender/Pre.jsx new file mode 100644 index 0000000..09fb4d3 --- /dev/null +++ b/src/components/MarkdownRender/Pre.jsx @@ -0,0 +1,43 @@ +import { useEffect, useRef, useState } from 'react' +import CopyButton from '../CopyButton' +import PropTypes from 'prop-types' +import { changeChildrenFontSize } from '../../utils' + +export function Pre({ className, children }) { + const preRef = useRef(null) + const [fontSize, setFontSize] = useState(14) + const sizeList = [10, 12, 14, 16, 18] + + useEffect(() => { + changeChildrenFontSize(preRef.current.childNodes[1], fontSize + 'px') + }) + + return ( +
+
+
+ preRef.current.childNodes[1].textContent} size={14} />
+
+ {children}
+
+ )
+}
+
+Pre.propTypes = {
+ className: PropTypes.string.isRequired,
+ children: PropTypes.object.isRequired,
+}
diff --git a/src/components/MarkdownRender/markdown-without-katex.jsx b/src/components/MarkdownRender/markdown-without-katex.jsx
index 350ba8d..50ac088 100644
--- a/src/components/MarkdownRender/markdown-without-katex.jsx
+++ b/src/components/MarkdownRender/markdown-without-katex.jsx
@@ -3,28 +3,7 @@ import rehypeRaw from 'rehype-raw'
import rehypeHighlight from 'rehype-highlight'
import remarkGfm from 'remark-gfm'
import remarkBreaks from 'remark-breaks'
-import CopyButton from '../CopyButton'
-import { useRef } from 'react'
-import PropTypes from 'prop-types'
-
-function Pre({ className, children }) {
- const preRef = useRef(null)
- return (
- -- ) -} - -Pre.propTypes = { - className: PropTypes.string.isRequired, - children: PropTypes.object.isRequired, -} +import { Pre } from './Pre' export function MarkdownRender(props) { const linkProperties = { diff --git a/src/components/MarkdownRender/markdown.jsx b/src/components/MarkdownRender/markdown.jsx index bc32f32..493b1f9 100644 --- a/src/components/MarkdownRender/markdown.jsx +++ b/src/components/MarkdownRender/markdown.jsx @@ -6,28 +6,7 @@ import rehypeKatex from 'rehype-katex' import remarkMath from 'remark-math' import remarkGfm from 'remark-gfm' import remarkBreaks from 'remark-breaks' -import CopyButton from '../CopyButton' -import { useRef } from 'react' -import PropTypes from 'prop-types' - -function Pre({ className, children }) { - const preRef = useRef(null) - return ( -preRef.current.textContent} - size={14} - /> - {children} -
-- ) -} - -Pre.propTypes = { - className: PropTypes.string.isRequired, - children: PropTypes.object.isRequired, -} +import { Pre } from './Pre' export function MarkdownRender(props) { const linkProperties = { diff --git a/src/content-script/styles.scss b/src/content-script/styles.scss index 2e7aaf8..0bec176 100644 --- a/src/content-script/styles.scss +++ b/src/content-script/styles.scss @@ -112,11 +112,32 @@ animation: chatgptbox-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; } - .code-copy-btn { + .code-corner-util { color: inherit; position: absolute; right: 10px; top: 3px; + } + + .gpt-util-group { + display: flex; + gap: 15px; + align-items: center; + } + + .gpt-util-icon { + display: flex; + cursor: pointer; + align-items: center; + } + + .normal-button { + padding: 1px 6px; + border: 1px solid; + border-color: var(--theme-border-color); + background-color: var(--theme-color); + color: var(--font-color); + border-radius: 5px; cursor: pointer; } @@ -127,6 +148,7 @@ word-break: break-word; pre { margin-top: 10px; + padding: 0; } & > p { @@ -168,28 +190,6 @@ .gpt-feedback-selected { color: #f08080; } - - .gpt-util-group { - display: flex; - gap: 15px; - align-items: center; - } - - .gpt-util-icon { - display: flex; - cursor: pointer; - align-items: center; - } - - .normal-button { - padding: 1px 6px; - border: 1px solid; - border-color: var(--theme-border-color); - background-color: var(--theme-color); - color: var(--font-color); - border-radius: 5px; - cursor: pointer; - } } .error { diff --git a/src/utils/change-children-font-size.mjs b/src/utils/change-children-font-size.mjs new file mode 100644 index 0000000..b65f236 --- /dev/null +++ b/src/utils/change-children-font-size.mjs @@ -0,0 +1,10 @@ +export function changeChildrenFontSize(element, size) { + try { + element.style.fontSize = size + } catch { + /* empty */ + } + for (let i = 0; i < element.childNodes.length; i++) { + changeChildrenFontSize(element.childNodes[i], size) + } +} diff --git a/src/utils/index.mjs b/src/utils/index.mjs index b645e06..126c84b 100644 --- a/src/utils/index.mjs +++ b/src/utils/index.mjs @@ -1,3 +1,4 @@ +export * from './change-children-font-size' export * from './create-element-at-position' export * from './crop-text' export * from './ends-with-question-mark'preRef.current.textContent} - size={14} - /> - {children} -