Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trailing slash to site links within markdown #534

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/example/workspace-docs/02-markdown-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,11 @@ will be rendered as
```DSL
"generatr.markdown.flexmark.extensions" "GfmTaskList"
```

### Links to Markdown documents

Placing links on markdown pages is easy. You can link to:

* an overview page like [Workspace decisions](/decisions/),
* an individual decision [ADR-0001. record architecture decisions](/decisions/1/)
* or some system documentation like [Internet Banking](/internet-banking-system/).
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import kotlinx.html.stream.createHTML
import net.sourceforge.plantuml.FileFormat
import net.sourceforge.plantuml.FileFormatOption
import net.sourceforge.plantuml.SourceStringReader
import nl.avisi.structurizr.site.generatr.site.asUrlToDirectory
import nl.avisi.structurizr.site.generatr.site.asUrlToFile
import nl.avisi.structurizr.site.generatr.site.views.diagram
import org.asciidoctor.Options
Expand Down Expand Up @@ -134,7 +135,14 @@ private class CustomLinkResolver(private val pageViewModel: PageViewModel) : Lin
return link

return link.withStatus(LinkStatus.VALID)
.withUrl("/${link.url.dropWhile { it == '/' }}".asUrlToFile(pageViewModel.url))
.withUrl("/${link.url.dropWhile { it == '/' }}"
.let {
if (it.endsWith('/'))
it.asUrlToDirectory(pageViewModel.url)
else
it.asUrlToFile(pageViewModel.url)
}
)
}

class Factory(private val viewModel: PageViewModel) : LinkResolverFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,50 @@ class MarkdownToHtmlTest : ViewModelTest() {
""".trimIndent()
)
}

@Test
fun `links to pages`() {
val generatorContext = generatorContext()
val viewModel = HomePageViewModel(generatorContext)

val html = toHtml(
viewModel,
"""
## header
Link: [Some decision](/decisions/1/),
""".trimIndent(),
Format.Markdown,
svgFactory
)

assertThat(html).isEqualTo(
"""
<h2>header</h2>
<p>Link: <a href="decisions/1/">Some decision</a>,</p>
""".trimIndent()
)
}

@Test
fun `links to files`() {
val generatorContext = generatorContext()
val viewModel = HomePageViewModel(generatorContext)

val html = toHtml(
viewModel,
"""
## header
Link: [Some document](/document.md),
""".trimIndent(),
Format.Markdown,
svgFactory
)

assertThat(html).isEqualTo(
"""
<h2>header</h2>
<p>Link: <a href="document.md">Some document</a>,</p>
""".trimIndent()
)
}
}
Loading