Skip to content

Commit

Permalink
Markdown 새부 스타일 수정 (10.06)
Browse files Browse the repository at this point in the history
Markdown 새부 스타일 수정 (10.06)
  • Loading branch information
seoko97 authored Oct 6, 2023
2 parents 6c0236a + 5d8dee0 commit 06aa7ae
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 27 deletions.
5 changes: 1 addition & 4 deletions src/components/ui/Markdown/overrides/code/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ const code = ({ children, className = "", ...props }: IProps) => {
const language = className?.replace("lang-", "");

const isText = language === "txt" || language === "text";
const TXT_CLASS = isText
? "!text-markdown1 !transition-[color,background-color] !bg-markdown"
: "";

return language ? (
<SyntaxHighlighter
Expand All @@ -46,7 +43,7 @@ const code = ({ children, className = "", ...props }: IProps) => {
showInlineLineNumbers={true}
style={oneDark}
codeTagProps={{ className: "text-sm" }}
className={`relative w-full rounded-md !p-4 shadow-md !transition-[background-color] !text-shadow-none ${TXT_CLASS}`}
className="relative w-full rounded-md !p-4 shadow-md !transition-[background-color] !text-shadow-none"
>
{String(children).replace(/\n$/, "")}
</SyntaxHighlighter>
Expand Down
19 changes: 11 additions & 8 deletions src/components/ui/Markdown/overrides/img.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ const img = (props: ImageProps) => {
}

return (
<NextImage
alt={alt ?? "post_image"}
loading="lazy"
{...rest}
width={1000}
height={1000}
className="mx-auto my-0 h-auto w-auto max-w-full rounded-sm shadow-md"
/>
<>
<NextImage
alt={alt ?? "post_image"}
loading="lazy"
{...rest}
width={1000}
height={1000}
className="mx-auto my-0 h-auto w-auto max-w-full rounded-md shadow-sm"
/>
{alt && <p className="mt-2 text-center text-sm text-gray-400">{alt}</p>}
</>
);
};

Expand Down
12 changes: 2 additions & 10 deletions src/components/ui/Markdown/overrides/p.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import React from "react";

const p = (props: JSX.IntrinsicElements["p"]) => {
const { children, ...rest } = props;

const child = (children as JSX.Element[])?.[0];

if ((child && child.type === "p") || child.type === "div") {
return <>{props.children}</>;
}

return <p {...rest}>{props.children}</p>;
const p = ({ children, ...rest }: JSX.IntrinsicElements["p"]) => {
return <div {...rest}>{children}</div>;
};

export default p;
2 changes: 1 addition & 1 deletion src/components/ui/client/post/PostContent/Toc/item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const TocItem = ({ item, isActive, onClick }: IProps) => {
return (
<li
style={{ paddingLeft: `${level * 0.8}rem` }}
className={`${className} w-full [&.active>a]:text-primary [&.active]:-translate-x-1`}
className={`${className} w-full [&.active>a]:text-effect1`}
>
<a
id={id}
Expand Down
19 changes: 16 additions & 3 deletions src/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
@apply mt-0;
}

& p {
& div {
@apply relative;
}

Expand Down Expand Up @@ -187,7 +187,7 @@
& h4,
& h5,
& h6,
& p,
& div,
& td,
& ul,
& ol {
Expand All @@ -196,7 +196,7 @@
@apply break-all transition-[color];
}

& p,
& div,
& ul,
& ol,
& table,
Expand Down Expand Up @@ -235,5 +235,18 @@
& a {
@apply text-teal-400 hover:underline;
}

& table {
@apply w-full text-primary transition-[color];

& td {
@apply border-x-0;
}

& td,
& th {
@apply p-2;
}
}
}
}
4 changes: 3 additions & 1 deletion src/utils/getChildrenText.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import removeMd from "remove-markdown";

const getChildrenText = (node: React.ReactElement): string => {
if (typeof node === "string") {
const text = (node as string).replace(/[{}[\]/?.,;:|)*~`!^\-_+<>@#$%&\\=('"]/g, " ");
const text = removeMd(node);
return text;
}

Expand Down

0 comments on commit 06aa7ae

Please sign in to comment.