mirror of https://github.com/usbharu/Hideout.git
Apply suggestions from code review
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
parent
06ce40991c
commit
5a4f6c0733
|
@ -11,7 +11,6 @@ import org.springframework.stereotype.Service
|
||||||
@Service
|
@Service
|
||||||
class DefaultPostContentFormatter(private val policyFactory: PolicyFactory) : PostContentFormatter {
|
class DefaultPostContentFormatter(private val policyFactory: PolicyFactory) : PostContentFormatter {
|
||||||
override fun format(content: String): FormattedPostContent {
|
override fun format(content: String): FormattedPostContent {
|
||||||
|
|
||||||
// まず不正なHTMLを整形する
|
// まず不正なHTMLを整形する
|
||||||
val document = Jsoup.parseBodyFragment(content)
|
val document = Jsoup.parseBodyFragment(content)
|
||||||
val outputSettings = Document.OutputSettings()
|
val outputSettings = Document.OutputSettings()
|
||||||
|
@ -24,7 +23,6 @@ class DefaultPostContentFormatter(private val policyFactory: PolicyFactory) : Po
|
||||||
""
|
""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
// 文字だけのHTMLなどはここでpタグで囲む
|
// 文字だけのHTMLなどはここでpタグで囲む
|
||||||
val flattenHtml = unsafeElement.childNodes().mapNotNull {
|
val flattenHtml = unsafeElement.childNodes().mapNotNull {
|
||||||
if (it is Element) {
|
if (it is Element) {
|
||||||
|
@ -36,7 +34,6 @@ class DefaultPostContentFormatter(private val policyFactory: PolicyFactory) : Po
|
||||||
}
|
}
|
||||||
}.filter { it.text().isNotBlank() }
|
}.filter { it.text().isNotBlank() }
|
||||||
|
|
||||||
|
|
||||||
// HTMLのサニタイズをする
|
// HTMLのサニタイズをする
|
||||||
val unsafeHtml = Elements(flattenHtml).outerHtml()
|
val unsafeHtml = Elements(flattenHtml).outerHtml()
|
||||||
|
|
||||||
|
@ -47,7 +44,6 @@ class DefaultPostContentFormatter(private val policyFactory: PolicyFactory) : Po
|
||||||
|
|
||||||
val formattedHtml = mutableListOf<Element>()
|
val formattedHtml = mutableListOf<Element>()
|
||||||
|
|
||||||
|
|
||||||
// 連続するbrタグを段落に変換する
|
// 連続するbrタグを段落に変換する
|
||||||
for (element in safeDocument.children()) {
|
for (element in safeDocument.children()) {
|
||||||
var brCount = 0
|
var brCount = 0
|
||||||
|
@ -64,7 +60,6 @@ class DefaultPostContentFormatter(private val policyFactory: PolicyFactory) : Po
|
||||||
formattedHtml.add(Element("p").appendChildren(childNodes.subList(prevIndex, childNodes.size)))
|
formattedHtml.add(Element("p").appendChildren(childNodes.subList(prevIndex, childNodes.size)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
val elements = Elements(formattedHtml)
|
val elements = Elements(formattedHtml)
|
||||||
|
|
||||||
return FormattedPostContent(elements.outerHtml().replace("\n", ""), printHtml(elements))
|
return FormattedPostContent(elements.outerHtml().replace("\n", ""), printHtml(elements))
|
||||||
|
|
Loading…
Reference in New Issue