From 85ad862b1cfdcdc6d4f6df6779e8fe49ca223967 Mon Sep 17 00:00:00 2001 From: Dmitry Pavlov Date: Fri, 5 Jan 2024 21:28:46 +0300 Subject: [PATCH] Passing xrefstyle attribute value to generate xreftext Fixes #136 --- .gitignore | 6 +++ CHANGELOG.md | 4 ++ .../zeldigas/text2confl/asciidoc/helpers.rb | 4 +- .../convert/asciidoc/RenderingOfLinksTest.kt | 37 +++++++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index f83e8cf0..ce26f81c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ .idea target *.iml + +.flattened-pom.xml +.asciidoctor +.asciidoc +.diagrams +out \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index cdeee0f5..cb500496 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## Unreleased +### Fixed + +- \[AsciiDoc] `xrefstyle` attribute is taken into account for references (#136) + ## 0.15.1 - 2024-01-02 ### Fixed diff --git a/convert/src/main/resources/com/github/zeldigas/text2confl/asciidoc/helpers.rb b/convert/src/main/resources/com/github/zeldigas/text2confl/asciidoc/helpers.rb index 8d554307..480f6ceb 100644 --- a/convert/src/main/resources/com/github/zeldigas/text2confl/asciidoc/helpers.rb +++ b/convert/src/main/resources/com/github/zeldigas/text2confl/asciidoc/helpers.rb @@ -177,7 +177,7 @@ def resolve_link(target) def xref_text empty_fallback if attributes[:refid] == text ref = document.catalog[:refs][attributes['refid'] || target] - str = (ref ? ref.xreftext : empty_fallback || text) + str = (ref ? ref.xreftext(attr 'xrefstyle', nil, true) : empty_fallback || text) else str = text end @@ -268,7 +268,7 @@ def confluence_inline_quoted node # @param text [String] def link_content text - if text.include? '<' + if text.include?('<') || text.include?('&#') %(#{text}) else %() diff --git a/convert/src/test/kotlin/com/github/zeldigas/text2confl/convert/asciidoc/RenderingOfLinksTest.kt b/convert/src/test/kotlin/com/github/zeldigas/text2confl/convert/asciidoc/RenderingOfLinksTest.kt index 7b243219..b25d0bb6 100644 --- a/convert/src/test/kotlin/com/github/zeldigas/text2confl/convert/asciidoc/RenderingOfLinksTest.kt +++ b/convert/src/test/kotlin/com/github/zeldigas/text2confl/convert/asciidoc/RenderingOfLinksTest.kt @@ -4,6 +4,7 @@ import assertk.assertThat import com.github.zeldigas.text2confl.convert.Attachment import com.github.zeldigas.text2confl.convert.PageHeader import com.github.zeldigas.text2confl.convert.confluence.ReferenceProvider +import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test import kotlin.io.path.Path @@ -166,6 +167,42 @@ internal class RenderingOfLinksTest : RenderingTestBase() { """.trimIndent(), ) } + + @Test + @Tag("GH-136") + fun `Xrefstyle is used for xref rendering`() { + val result = toHtml( + """ + = Document + :sectnums: + :xrefstyle: full + + == test + + As it was described in <> + + == another + + section + """.trimIndent(), + referenceProvider = AsciidocReferenceProvider( + Path("./test.adoc"), + ReferenceProvider.fromDocuments( + Path("."), emptyMap() + ) + ) + ) + + assertThat(result).isEqualToConfluenceFormat( + """ +

1. testtest

+

As it was described in Section 2, “another”

+

2. anotheranother

+

section

+ """.trimIndent(), + ) + + } }