Skip to content

Commit

Permalink
fix: resolving documents with spaces in dir/files (they must be urlen…
Browse files Browse the repository at this point in the history
…coded in text)

Fixes #83
  • Loading branch information
zeldigas committed Jan 7, 2024
1 parent 0775bbc commit 2031d4c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Fixed

- handling of links with spaces for both Markdown and AsciiDoc. Such links need to be specified urlencoded (
e.g. `dir%20with%20space/my-doc.md` for file in `dir with space` directory) and now file is properly resolved.
- \[AsciiDoc] `xrefstyle` attribute is taken into account for references (#136)

## 0.15.1 - 2024-01-02
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.zeldigas.text2confl.convert.confluence

import com.github.zeldigas.text2confl.convert.PageHeader
import io.github.oshai.kotlinlogging.KotlinLogging
import java.net.URLDecoder
import java.nio.file.Path
import kotlin.io.path.relativeTo

Expand Down Expand Up @@ -52,9 +53,10 @@ class ReferenceProviderImpl(private val basePath: Path, documents: Map<Path, Pag
log.debug { "$refTo detected as link in $source" }
return null
}
if (refTo.startsWith("#")) return Anchor(refTo.substring(1))
val normalizedRef = URLDecoder.decode(refTo, "UTF-8")
if (normalizedRef.startsWith("#")) return Anchor(normalizedRef.substring(1))

val parts = refTo.split("#", limit = 2)
val parts = normalizedRef.split("#", limit = 2)
val ref = parts[0]
val anchor = parts.getOrNull(1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ internal class RenderingOfLinksTest : RenderingTestBase() {
link:test/another.md#first-header[Link with anchor to another type via link macro]
xref:test/another.md#first-header[Link [.line-through]#with# **anchor** to `another type`]
xref:test/another.md#first-header[Link [.line-through]#with# **anchor** to `another type`]
xref:a%20spaced/file.md#first-header[Link to spaced file]
""".trimIndent(),
referenceProvider = AsciidocReferenceProvider(
Path("./test.adoc"),
ReferenceProvider.fromDocuments(
Path("."), mapOf(
Path("src.adoc") to PageHeader("Test", emptyMap()),
Path("another.adoc") to PageHeader("Another adoc", emptyMap()),
Path("test/another.md") to PageHeader("Markdown", emptyMap())
Path("test/another.md") to PageHeader("Markdown", emptyMap()),
Path("a spaced/file.md") to PageHeader("File in spaced dir", emptyMap())
)
)
)
Expand All @@ -49,6 +52,7 @@ internal class RenderingOfLinksTest : RenderingTestBase() {
<p><ac:link ac:anchor="first-header"><ri:page ri:content-title="Markdown" ri:space-key="TEST" /><ac:plain-text-link-body><![CDATA[Link with anchor to another type]]></ac:plain-text-link-body></ac:link></p>
<p><ac:link ac:anchor="first-header"><ri:page ri:content-title="Markdown" ri:space-key="TEST" /><ac:plain-text-link-body><![CDATA[Link with anchor to another type via link macro]]></ac:plain-text-link-body></ac:link></p>
<p><ac:link ac:anchor="first-header"><ri:page ri:content-title="Markdown" ri:space-key="TEST" /><ac:link-body>Link <del>with</del> <strong>anchor</strong> to <code>another type</code></ac:link-body></ac:link></p>
<p><ac:link ac:anchor="first-header"><ri:page ri:content-title="File in spaced dir" ri:space-key="TEST" /><ac:plain-text-link-body><![CDATA[Link to spaced file]]></ac:plain-text-link-body></ac:link></p>
""".trimIndent(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal class ReferenceProviderImplTest {
doc("docs/sub1/one.md", "Sub1 Title One"),
doc("docs/sub/sub/a.md", "SubSub A"),
doc("docs/sub/sub1/a.md", "SubSub1 A"),
doc("docs/a spaced/a.md", "Spaced dir file"),
)
)

Expand All @@ -38,6 +39,7 @@ internal class ReferenceProviderImplTest {
"docs/one.md,sub/one.md,Sub Title One",
"docs/one.md,sub/sub/../one.md,Sub Title One",
"docs/one.md,sub/sub/a.md,SubSub A",
"docs/one.md,a%20spaced/a.md,Spaced dir file",
"docs/sub/two.md,one.md,Sub Title One",
"docs/sub/two.md,./one.md,Sub Title One",
"docs/sub/two.md,sub/one.md,",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ internal class RenderingOfLinksTest : RenderingTestBase() {
[Link ~~with~~ **anchor** to `another type`][ref2]
[Link to spaced file](a%20spaced/file.md#first-header)
[ref1]: another.md#test
[ref2]: test/another.adoc#first-header
""".trimIndent(),
referenceProvider = ReferenceProvider.fromDocuments(
Path("."), mapOf(
Path("src.md") to PageHeader("Test", emptyMap()),
Path("another.md") to PageHeader("Another md", emptyMap()),
Path("test/another.adoc") to PageHeader("Asciidoc", emptyMap())
Path("test/another.adoc") to PageHeader("Asciidoc", emptyMap()),
Path("a spaced/file.md") to PageHeader("File in spaced dir", emptyMap())
)
)
)
Expand All @@ -45,6 +48,7 @@ internal class RenderingOfLinksTest : RenderingTestBase() {
<p><ac:link ac:anchor="first-header"><ri:page ri:content-title="Asciidoc" ri:space-key="TEST" /><ac:link-body>Link <del>with</del> <strong>anchor</strong> to <code>another type</code></ac:link-body></ac:link></p>
<p><ac:link ac:anchor="test"><ri:page ri:content-title="Another md" ri:space-key="TEST" /><ac:plain-text-link-body><![CDATA[Link with anchor]]></ac:plain-text-link-body></ac:link></p>
<p><ac:link ac:anchor="first-header"><ri:page ri:content-title="Asciidoc" ri:space-key="TEST" /><ac:link-body>Link <del>with</del> <strong>anchor</strong> to <code>another type</code></ac:link-body></ac:link></p>
<p><ac:link ac:anchor="first-header"><ri:page ri:content-title="File in spaced dir" ri:space-key="TEST" /><ac:plain-text-link-body><![CDATA[Link to spaced file]]></ac:plain-text-link-body></ac:link></p>
""".trimIndent(),
)
}
Expand Down

0 comments on commit 2031d4c

Please sign in to comment.