Skip to content

Commit

Permalink
refactor: html 테그 클래스 지정 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
belljun3395 committed Jul 3, 2024
1 parent 9940907 commit 7f5053e
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))
}

0 comments on commit 7f5053e

Please sign in to comment.