Skip to content

Commit

Permalink
removed extra spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelUnkey committed Aug 14, 2024
1 parent c9891c8 commit 997813a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
28 changes: 20 additions & 8 deletions apps/www/components/template/codeblock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,29 @@ import React, { useState } from "react";
import SyntaxHighlighter from "react-syntax-highlighter";

export function CodeBlock(props: any) {
let language = props.node.children[0].properties?.className;
let language = props.node.children[0].properties?.className.toString().replace(/language-/, "");
// for some reason... occasionally for no reason at all. the className is not in the properties
if (!language) {
language = ["language-jsx"];
language = ["jsx"];
}

const block =
props.node.children[0].properties?.value ||
props.node.children[0].children[0].value.trim().replace(/\s+/g, "\n");
const preTrimBlock =
props.node.children[0].properties?.value || props.node.children[0].children[0].value.trim();

const splitArray = preTrimBlock.split("\n");
// Initialize an empty string
let temp = "";

// Loop through the array and append each element followed by a newline character
for (const element of splitArray) {
temp += `${element.trim()}\n`;
}

// Remove the trailing newline character if needed
if (temp.endsWith("\n")) {
temp = temp.slice(0, -1).trim();
}
const block = temp;
const [copyData, _setCopyData] = useState(block);
function handleDownload() {
const element = document.createElement("a");
Expand Down Expand Up @@ -45,14 +58,13 @@ export function CodeBlock(props: any) {
</button>
</div>
<SyntaxHighlighter
language={language.toString().replace(/language-/, "")}
language={language}
style={darkTheme}
showLineNumbers={true}
wrapLongLines={false}
customStyle={{ margin: 0, padding: "1rem" }}
{...props}
codeTagProps={{
style: { backgroundColor: "transparent", margin: 0, padding: 0 },
style: { backgroundColor: "transparent", paddingLeft: 0 },
}}
>
{block}
Expand Down
2 changes: 1 addition & 1 deletion apps/www/components/template/mdx-components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const TemplateComponents = {
hr: (_props: any) => <Separator orientation="horizontal" />,
code: (props: any) => (
<code
className="px-2 py-1 font-medium text-gray-600 border border-gray-200 rounded-md bg-gray-50 before:hidden after:hidden"
className="px-2 py-1 font-medium text-gray-600 border border-gray-200 rounded-md bg-gray-50 "
{...props}
/>
),
Expand Down

0 comments on commit 997813a

Please sign in to comment.