From 7f5053e26f8ba7164e11d792cd75632c05b60f6d Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Wed, 3 Jul 2024 22:32:36 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20html=20=ED=85=8C=EA=B7=B8=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=A7=80=EC=A0=95=20=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConvertDocumentService.kt | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/storage/src/main/kotlin/com/few/storage/document/service/ConvertDocumentService.kt b/storage/src/main/kotlin/com/few/storage/document/service/ConvertDocumentService.kt index fddf3582a..0922e7e79 100644 --- a/storage/src/main/kotlin/com/few/storage/document/service/ConvertDocumentService.kt +++ b/storage/src/main/kotlin/com/few/storage/document/service/ConvertDocumentService.kt @@ -4,6 +4,7 @@ import org.commonmark.parser.Parser import org.commonmark.renderer.html.HtmlRenderer import org.jsoup.Jsoup import org.springframework.stereotype.Service +import java.io.File @Service class ConvertDocumentService { @@ -17,7 +18,27 @@ class ConvertDocumentService { fun mdToHtml(md: String): String { val html = Jsoup.parse(ARTICLE) val article = htmlRenderer.render(parser.parse(md)) - html.body().append(article) - return html.toString() + html.getElementsByTag("article").append(article) + html.getElementsByTag("h1").forEach { + it.addClass("sub1-semibold") + } + html.getElementsByTag("h2").forEach { + it.addClass("sub1-semibold top bottom 5px") + } + html.getElementsByTag("h3").forEach { + it.addClass("sub1-semibold") + } + html.getElementsByTag("img").forEach { + it.addClass("!max-h-[260px] object-contain") + } + return html.body().html() } +} + +fun main() { + val convertDocumentService = ConvertDocumentService() + val file = + File("/Users/jongjun/Documents/Code/Spring/24th-Web-Team-1-BE/storage/src/main/resources/test.md") + val md = file.readText() + println(convertDocumentService.mdToHtml(md)) } \ No newline at end of file