Skip to content

Commit bd6e264

Browse files
authored
Merge pull request #214 from Moaguide-develop/feat/articleDetail
Fix: html parse max-w, left style setArrtibute
2 parents 00ca11f + 8a2fe66 commit bd6e264

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

src/components/learning/article/ArticleDetailContent.tsx

+27-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
'use client';
22

33
import { useRouter } from "next/navigation";
4-
import Image from "next/image";
5-
import { getValidImageSrc } from "@/utils/checkImageProperty";
64

75
interface ContentProps {
86
text?: string;
@@ -23,16 +21,40 @@ const ArticleDetailContent = ({ text, title, paywallUp, createdAt, authorName, i
2321

2422
const parseHtmlContent = (htmlContent: string): string => {
2523
if (!htmlContent) return "";
26-
24+
2725
try {
2826
const parser = new DOMParser();
2927
const doc = parser.parseFromString(htmlContent, "text/html");
30-
return doc.body.innerHTML;
28+
29+
doc.querySelectorAll("[class*='max-w-[']").forEach((el) => {
30+
const classList = el.getAttribute("class") || "";
31+
const match = classList.match(/max-w-\[(\d+)px\]/);
32+
33+
if (match) {
34+
const maxWidth = match[1];
35+
(el as HTMLElement).style.maxWidth = `${maxWidth}px`;
36+
el.setAttribute("class", classList.replace(match[0], "").trim());
37+
}
38+
});
39+
40+
doc.querySelectorAll("[class*='left-[']").forEach((el) => {
41+
const classList = el.getAttribute("class") || "";
42+
const match = classList.match(/left-\[(\d+)px\]/);
43+
44+
if (match) {
45+
const leftValue = parseInt(match[1], 10) + 15;
46+
(el as HTMLElement).style.left = `${leftValue}px`;
47+
el.setAttribute("class", classList.replace(match[0], "").trim());
48+
}
49+
});
50+
51+
return doc.body.innerHTML;
3152
} catch (error) {
3253
console.error("HTML 파싱 중 오류 발생:", error);
33-
return htmlContent;
54+
return htmlContent;
3455
}
3556
};
57+
3658

3759
const parsedPaywallContent = paywallUp ? parseHtmlContent(paywallUp) : null;
3860
const parsedTextContent = text ? parseHtmlContent(text) : null;
@@ -43,11 +65,6 @@ const ArticleDetailContent = ({ text, title, paywallUp, createdAt, authorName, i
4365
{new Date(createdAt).toLocaleDateString()} <br />
4466
BY. {authorName}
4567
</p>
46-
{/* <Image
47-
src={getValidImageSrc(imgLink)}
48-
alt={title}
49-
className="w-full max-w-[650px] aspect-square my-16 object-cover mx-auto rounded-lg"
50-
/> */}
5168
{isPremium ? (
5269
<>
5370
<article

tailwind.config.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import type { Config } from 'tailwindcss';
22

33
const config: Config = {
44
content: [
5-
'./src/pages/**/*.{js,ts,jsx,tsx,mdx}',
6-
'./src/components/**/*.{js,ts,jsx,tsx,mdx}',
7-
'./src/app/**/*.{js,ts,jsx,tsx,mdx}'
5+
'./src/**/*.{js,ts,jsx,tsx,mdx,html}',
6+
'./public/**/*.html',
7+
'./utils/**/*.{js,ts}',
8+
'./server/**/*.{js,ts}',
89
],
910
theme: {
1011
extend: {

0 commit comments

Comments
 (0)