From 7c41d0031e995e0eba81b48cf447795ca3a02a1a Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Wed, 14 Aug 2024 14:58:36 +0200 Subject: [PATCH] Avoid HTML tags in AsciiDoc titles --- .../structurizr/site/generatr/site/model/ContentTitle.kt | 6 +++--- .../site/generatr/site/model/ContentTitleTest.kt | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/ContentTitle.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/ContentTitle.kt index d14d1f36..47157c93 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/ContentTitle.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/ContentTitle.kt @@ -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" } diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/ContentTitleTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/ContentTitleTest.kt index 988f91db..b4abf102 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/ContentTitleTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/ContentTitleTest.kt @@ -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 { @@ -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") + } }