This commit is contained in:
Anang Yusman 2025-10-15 13:47:11 +08:00
parent 5827fdb1e4
commit b5f96d53ed
2 changed files with 27 additions and 2 deletions

View File

@ -313,6 +313,23 @@ export default function DetailContent() {
);
}
function decodeHtmlString(raw: string = "") {
if (!raw) return "";
// 1⃣ Hapus newline escape, backslash, dsb
let decoded = raw
.replace(/\\n/g, "\n")
.replace(/\\"/g, '"') // ubah \" jadi "
.replace(/\\'/g, "'") // ubah \' jadi '
.replace(/\\\\/g, "\\") // ubah \\ jadi \
.trim();
// 2⃣ Decode entity HTML (misal ")
const el = document.createElement("textarea");
el.innerHTML = decoded;
return el.value;
}
return (
<>
<div className="bg-white grid grid-cols-1 md:grid-cols-3 gap-6 px-8 py-8">
@ -472,7 +489,9 @@ export default function DetailContent() {
<div className="text-gray-700 leading-relaxed text-justify">
<div
dangerouslySetInnerHTML={{
__html: articleDetail?.htmlDescription || "",
__html: decodeHtmlString(
articleDetail?.htmlDescription || ""
),
}}
/>
</div>

View File

@ -193,7 +193,13 @@ export default function EditArticleForm(props: { isDetail: boolean }) {
setValue("customCreatorName", data?.customCreatorName);
setValue("slug", data?.slug);
setValue("source", data?.source);
setValue("description", data?.htmlDescription);
const cleanDescription = data?.htmlDescription
? data.htmlDescription
.replace(/\\"/g, '"')
.replace(/\\n/g, "\n", "\\") // ubah newline escaped
.trim()
: "";
setValue("description", cleanDescription);
setValue("tags", data?.tags ? data.tags.split(",") : []);
setThumbnail(data?.thumbnailUrl);
setDiseId(data?.aiArticleId);