From dcbb80a1f7678b9bc49675149a6daf8699fd2ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filippa=20H=C3=B6gn=C3=A4sbacka?= Date: Sun, 30 Nov 2025 15:52:37 +0000 Subject: [PATCH] Revert "added fix and tests for console errors" This reverts commit 9f89e552d4df3ef2341ca6dcc6d96d636de30eb0. --- .../components/ui/render-html/render-html.jsx | 47 ++++++------------- .../ui/render-html/render-html.test.jsx | 35 -------------- 2 files changed, 15 insertions(+), 67 deletions(-) diff --git a/gradesa/src/components/ui/render-html/render-html.jsx b/gradesa/src/components/ui/render-html/render-html.jsx index 95c11b1..a497113 100644 --- a/gradesa/src/components/ui/render-html/render-html.jsx +++ b/gradesa/src/components/ui/render-html/render-html.jsx @@ -1,56 +1,39 @@ -import parse, { domToReact, Element } from "html-react-parser"; +import parse, { domToReact } from "html-react-parser"; import { GlossaryParagraph, GlossaryListItem, } from "@/components/ui/glossary/GlossaryText"; -// Korvataan allaolevat custom-tagit vastaavilla HTML-tageilla jotta console errorit saadaan pois: -const tagMapToHtml = { - container: "div", - column: "div", - anchor: "a", -}; - export default function RenderHTML({ data }) { - if (!data) return null; + if (!data) { + return null; + } + // Parse HTML and replace custom glossary tags with React components const parsedContent = parse(data, { replace: (domNode) => { - if (domNode.type !== "tag") return; + // Only process element nodes, not text or comment nodes + if (domNode.type !== "tag") { + return; + } - const name = domNode.name?.toLowerCase(); - - if (name === "glossaryparagraph") { + // Handle GlossaryParagraph custom tags + if (domNode.name === "glossaryparagraph") { + // Extract and convert child nodes to React, preserving HTML structure const children = domNode.children ? domToReact(domNode.children) : null; return ( {children} ); } - if (name === "glossarylistitem") { + // Handle GlossaryListItem custom tags + if (domNode.name === "glossarylistitem") { + // Extract and convert child nodes to React, preserving HTML structure const children = domNode.children ? domToReact(domNode.children) : null; return ( {children} ); } - - // Muut custom-tagit -> standardi HTML - if (name in tagMapToHtml) { - const HtmlTag = tagMapToHtml[name]; - const children = domNode.children ? domToReact(domNode.children) : null; - return {children}; - } - - // Jos joku tuntematon tagi, normalisoidaan se diviksi - if ( - !/^(div|span|p|li|ul|ol|a|strong|em|h[1-6]|img|br|hr|table|thead|tbody|tr|td|th|code|pre|blockquote)$/.test( - name - ) - ) { - const children = domNode.children ? domToReact(domNode.children) : null; - return
{children}
; - } - return; }, }); diff --git a/gradesa/src/components/ui/render-html/render-html.test.jsx b/gradesa/src/components/ui/render-html/render-html.test.jsx index 249a234..aa55dc9 100644 --- a/gradesa/src/components/ui/render-html/render-html.test.jsx +++ b/gradesa/src/components/ui/render-html/render-html.test.jsx @@ -205,41 +205,6 @@ describe("RenderHTML Component", () => { expect(container.textContent).toContain("end"); expect(container.textContent).toContain("finish"); }); - - // Tests below are for the console errors regarding unknown tags: - - it("should map to
", () => { - const html = "Column content"; - const { container } = render(); - const div = container.querySelector("div"); - expect(div).toBeTruthy(); - expect(div.textContent).toBe("Column content"); - }); - - it("should map to