Skip to content

Commit

Permalink
Fix codeblock value having numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
vineethasok committed Nov 15, 2023
1 parent 3293ddc commit 5b3d945
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions src/components/CodeBlock/CodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,38 +104,30 @@ export const CodeBlock = ({
const [errorCopy, setErrorCopy] = useState(false);
const [wrap, setWrap] = useState(wrapLines);
const customStyle = useColorStyle(theme);
const ref = useRef<HTMLElement>(null);

const copyCodeToClipboard = async () => {
if (ref.current?.textContent) {
try {
await navigator.clipboard.writeText(ref.current.textContent);
if (typeof onCopy == "function") {
onCopy(ref.current.textContent);
}
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch (error) {
let message = "Unable to copy code";
if (error instanceof Error) message = error.message;
setErrorCopy(true);
if (typeof onCopyError === "function") {
onCopyError(message);
}
setTimeout(() => setErrorCopy(false), 2000);
try {
await navigator.clipboard.writeText(children);
if (typeof onCopy == "function") {
onCopy(children);
}
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch (error) {
let message = "Unable to copy code";
if (error instanceof Error) message = error.message;
setErrorCopy(true);
if (typeof onCopyError === "function") {
onCopyError(message);
}
setTimeout(() => setErrorCopy(false), 2000);
}
};
const wrapElement = () => {
setWrap(wrap => !wrap);
};

const CodeWithRef = (props: HTMLAttributes<HTMLElement>) => (
<CodeContent
{...props}
ref={ref}
/>
);
const CodeWithRef = (props: HTMLAttributes<HTMLElement>) => <CodeContent {...props} />;
return (
<CodeBlockContainer
$theme={theme}
Expand Down

0 comments on commit 5b3d945

Please sign in to comment.