Skip to content

Commit

Permalink
[fix] prevent translations to math formulas and code-blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
PrinOrange committed Aug 25, 2024
1 parent 2b04a51 commit bd1b158
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions components/mdx/PreWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@ const PreWrapper = ({ children }: { children: JSX.Element }) => {
{hovered && (
<Button
aria-label="Copy code"
className={`absolute top-2 right-2 h-8 w-8 rounded p-1 ${copied ? "text-green-500 hover:text-green-500" : ""}`}
className={`absolute top-2 right-2 h-8 w-8 rounded p-1 ${
copied ? "text-green-500 hover:text-green-500" : ""
}`}
onClick={onCopy}
variant={"outline"}
>
{copied ? <FaCheck /> : <IoCopyOutline />}
</Button>
)}
<pre className="flat-scrollbar-normal not-prose rounded-md bg-[#F6F8FA] p-2 text-sm selection:bg-gray-300 selection:text-inherit dark:bg-[#0d1117] dark:selection:bg-gray-700">
<pre
translate="no"
className="flat-scrollbar-normal not-prose rounded-md bg-[#F6F8FA] p-2 text-sm selection:bg-gray-300 selection:text-inherit dark:bg-[#0d1117] dark:selection:bg-gray-700"
>
{children}
</pre>
</div>
Expand Down
5 changes: 5 additions & 0 deletions components/mdx/Span.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const Span = (props: JSX.IntrinsicElements["h2"]) => {
return <span translate={props.className?.includes("katex") ? "no" : undefined} {...props} />;
};

export default Span;
2 changes: 2 additions & 0 deletions components/mdx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Blockquote from "./Blockquote";
import H2 from "./H2";
import ImageWrapper from "./ImageWrapper";
import PreWrapper from "./PreWrapper";
import Span from "./Span";
import TableWrapper from "./TableWrapper";

export const MDXComponentsSet = {
Expand All @@ -10,4 +11,5 @@ export const MDXComponentsSet = {
img: ImageWrapper,
h2: H2,
blockquote: Blockquote,
span: Span,
};

0 comments on commit bd1b158

Please sign in to comment.