Skip to content

Commit

Permalink
Avoid HTML tags in AsciiDoc titles
Browse files Browse the repository at this point in the history
  • Loading branch information
jenspav committed Aug 14, 2024
1 parent fb56c10 commit 7c41d00
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ private fun Section.markdownTitle(): String {

val header = document.children.firstOrNull { it is Heading }?.let { it as Heading }
if (header != null)
return header.text.toString()
return header.text.toString().trim()

return "untitled document"
}

private fun Section.asciidocTitle(): String {
val options = Options.builder().safe(SafeMode.SERVER).build()
val options = Options.builder().safe(SafeMode.SERVER).backend("text").build()
val document = asciidoctorWithTextConverter.load(content, options)

if (document.title != null && document.title.isNotEmpty())
return document.title
return document.title.trim()

return "untitled document"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.junit.jupiter.api.DynamicTest
import org.junit.jupiter.api.TestFactory
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource
import kotlin.test.Test

class ContentTitleTest {

Expand Down Expand Up @@ -51,4 +52,10 @@ class ContentTitleTest {
val section = Section(Format.AsciiDoc, content)
assertThat(section.contentTitle()).isEqualTo("header")
}

@Test
fun `with asciidoc heading including logo`() {
val section = Section(Format.AsciiDoc, "= image:logo.png[logo] header")
assertThat(section.contentTitle()).isEqualTo("header")
}
}

0 comments on commit 7c41d00

Please sign in to comment.