This commit is contained in:
Anang Yusman 2025-10-15 13:49:17 +08:00
parent db08a8051a
commit 87e391a5bf
2 changed files with 26 additions and 2 deletions

View File

@ -310,6 +310,22 @@ export default function DetailContent() {
// </div>
// );
// }
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 &quot;)
const el = document.createElement("textarea");
el.innerHTML = decoded;
return el.value;
}
return (
<>
@ -492,7 +508,9 @@ export default function DetailContent() {
<div className="prose max-w-none 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);