diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDecisionPageViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDecisionPageViewModel.kt index 96142f5c..96fd72e0 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDecisionPageViewModel.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDecisionPageViewModel.kt @@ -9,7 +9,12 @@ class SoftwareSystemDecisionPageViewModel( ) : SoftwareSystemPageViewModel(generatorContext, softwareSystem, Tab.DECISIONS) { override val url = url(softwareSystem, decision) - val content = markdownToHtml(this, decision.content, generatorContext.svgFactory) + val content = markdownToHtml(this, transformADRLinks(decision.content, softwareSystem), generatorContext.svgFactory) + + private fun transformADRLinks(content: String, softwareSystem: SoftwareSystem) = + content.replace("\\[(.*)]\\(#(\\d+)\\)".toRegex()) { + "[${it.groupValues[1]}](${url(softwareSystem, Tab.DECISIONS)}/${it.groupValues[2]})" + } companion object { fun url(softwareSystem: SoftwareSystem, decision: Decision) = diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDecisionPageViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDecisionPageViewModel.kt index 4239e5ea..af6fb873 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDecisionPageViewModel.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDecisionPageViewModel.kt @@ -8,7 +8,12 @@ class WorkspaceDecisionPageViewModel(generatorContext: GeneratorContext, decisio override val url = url(decision) override val pageSubTitle: String = decision.title - val content = markdownToHtml(this, decision.content, generatorContext.svgFactory) + val content = markdownToHtml(this, transformADRLinks(decision.content), generatorContext.svgFactory) + + private fun transformADRLinks(content: String) = + content.replace("\\[(.*)]\\(#(\\d+)\\)".toRegex()) { + "[${it.groupValues[1]}](decisions/${it.groupValues[2]})" + } companion object { fun url(decision: Decision) = "/decisions/${decision.id}" diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDecisionPageViewModelTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDecisionPageViewModelTest.kt index ee7999fa..92563b88 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDecisionPageViewModelTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDecisionPageViewModelTest.kt @@ -3,6 +3,8 @@ package nl.avisi.structurizr.site.generatr.site.model import assertk.assertThat import assertk.assertions.isEqualTo import nl.avisi.structurizr.site.generatr.normalize +import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemPageViewModel.Companion.url +import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemPageViewModel.Tab import kotlin.test.Test class SoftwareSystemDecisionPageViewModelTest : ViewModelTest() { @@ -25,7 +27,7 @@ class SoftwareSystemDecisionPageViewModelTest : ViewModelTest() { val viewModel = SoftwareSystemDecisionPageViewModel(generatorContext, softwareSystem, createDecision()) assertThat(viewModel.tabs.single { it.link.active }.tab) - .isEqualTo(SoftwareSystemPageViewModel.Tab.DECISIONS) + .isEqualTo(Tab.DECISIONS) } @Test @@ -35,4 +37,28 @@ class SoftwareSystemDecisionPageViewModelTest : ViewModelTest() { assertThat(viewModel.content).isEqualTo(markdownToHtml(viewModel, decision.content, svgFactory)) } + + + @Test + fun `link to other ADR`() { + val decision = createDecision().apply { + content = """ + Decision with [link to other ADR](#2). + [Web link](https://google.com) + [Internal link](#other-section) + """.trimIndent() + } + val viewModel = SoftwareSystemDecisionPageViewModel(generatorContext, softwareSystem, decision) + + assertThat(viewModel.content).isEqualTo( + markdownToHtml( + viewModel, """ + Decision with [link to other ADR](${url(softwareSystem, Tab.DECISIONS)}/2). + [Web link](https://google.com) + [Internal link](#other-section) + """.trimIndent(), + svgFactory + ) + ) + } } diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDecisionPageViewModelTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDecisionPageViewModelTest.kt index 5ba8e35f..e678dee1 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDecisionPageViewModelTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/WorkspaceDecisionPageViewModelTest.kt @@ -30,4 +30,27 @@ class WorkspaceDecisionPageViewModelTest : ViewModelTest() { assertThat(viewModel.content).isEqualTo(markdownToHtml(viewModel, decision.content, svgFactory)) } + + @Test + fun `link to other ADR`() { + val decision = createDecision().apply { + content = """ + Decision with [link to other ADR](#2). + [Web link](https://google.com) + [Internal link](#other-section) + """.trimIndent() + } + val viewModel = WorkspaceDecisionPageViewModel(generatorContext(), decision) + + assertThat(viewModel.content).isEqualTo( + markdownToHtml( + viewModel, """ + Decision with [link to other ADR](decisions/2). + [Web link](https://google.com) + [Internal link](#other-section) + """.trimIndent(), + svgFactory + ) + ) + } }