diff --git a/core/src/main/kotlin/eu/iamgio/quarkdown/ast/quarkdown/block/Aligned.kt b/core/src/main/kotlin/eu/iamgio/quarkdown/ast/quarkdown/block/Aligned.kt index a6c7f7d6..9cdba30a 100644 --- a/core/src/main/kotlin/eu/iamgio/quarkdown/ast/quarkdown/block/Aligned.kt +++ b/core/src/main/kotlin/eu/iamgio/quarkdown/ast/quarkdown/block/Aligned.kt @@ -2,6 +2,8 @@ package eu.iamgio.quarkdown.ast.quarkdown.block import eu.iamgio.quarkdown.ast.NestableNode import eu.iamgio.quarkdown.ast.Node +import eu.iamgio.quarkdown.rendering.representable.RenderRepresentable +import eu.iamgio.quarkdown.rendering.representable.RenderRepresentableVisitor import eu.iamgio.quarkdown.visitor.node.NodeVisitor /** @@ -17,9 +19,12 @@ data class Aligned( /** * Possible alignment types of an [Aligned] block. */ - enum class Alignment { - LEFT, + enum class Alignment : RenderRepresentable { + START, CENTER, - RIGHT, + END, + ; + + override fun accept(visitor: RenderRepresentableVisitor): T = visitor.visit(this) } } diff --git a/core/src/main/kotlin/eu/iamgio/quarkdown/rendering/html/CssRepresentableVisitor.kt b/core/src/main/kotlin/eu/iamgio/quarkdown/rendering/html/CssRepresentableVisitor.kt index 438cd503..cac76324 100644 --- a/core/src/main/kotlin/eu/iamgio/quarkdown/rendering/html/CssRepresentableVisitor.kt +++ b/core/src/main/kotlin/eu/iamgio/quarkdown/rendering/html/CssRepresentableVisitor.kt @@ -2,6 +2,7 @@ package eu.iamgio.quarkdown.rendering.html import eu.iamgio.quarkdown.ast.base.block.BlockQuote import eu.iamgio.quarkdown.ast.base.block.Table +import eu.iamgio.quarkdown.ast.quarkdown.block.Aligned import eu.iamgio.quarkdown.ast.quarkdown.block.Box import eu.iamgio.quarkdown.ast.quarkdown.block.Clipped import eu.iamgio.quarkdown.ast.quarkdown.block.Container @@ -35,6 +36,8 @@ class CssRepresentableVisitor : RenderRepresentableVisitor { override fun visit(alignment: Table.Alignment) = alignment.kebabCaseName + override fun visit(alignment: Aligned.Alignment) = alignment.kebabCaseName + override fun visit(borderStyle: Container.BorderStyle) = when (borderStyle) { Container.BorderStyle.NORMAL -> "solid" diff --git a/core/src/main/kotlin/eu/iamgio/quarkdown/rendering/html/QuarkdownHtmlNodeRenderer.kt b/core/src/main/kotlin/eu/iamgio/quarkdown/rendering/html/QuarkdownHtmlNodeRenderer.kt index 86de9553..51b51cd8 100644 --- a/core/src/main/kotlin/eu/iamgio/quarkdown/rendering/html/QuarkdownHtmlNodeRenderer.kt +++ b/core/src/main/kotlin/eu/iamgio/quarkdown/rendering/html/QuarkdownHtmlNodeRenderer.kt @@ -104,7 +104,7 @@ class QuarkdownHtmlNodeRenderer(context: Context) : BaseHtmlNodeRenderer(context } } - override fun visit(node: Aligned) = div("align align-" + node.alignment.name.lowercase(), node.children) + override fun visit(node: Aligned) = div("align align-${node.alignment.asCSS}", node.children) override fun visit(node: Stacked) = div("stack stack-${node.layout.asCSS}") { diff --git a/core/src/main/kotlin/eu/iamgio/quarkdown/rendering/representable/RenderRepresentableVisitor.kt b/core/src/main/kotlin/eu/iamgio/quarkdown/rendering/representable/RenderRepresentableVisitor.kt index fc99c941..e495d188 100644 --- a/core/src/main/kotlin/eu/iamgio/quarkdown/rendering/representable/RenderRepresentableVisitor.kt +++ b/core/src/main/kotlin/eu/iamgio/quarkdown/rendering/representable/RenderRepresentableVisitor.kt @@ -2,6 +2,7 @@ package eu.iamgio.quarkdown.rendering.representable import eu.iamgio.quarkdown.ast.base.block.BlockQuote import eu.iamgio.quarkdown.ast.base.block.Table +import eu.iamgio.quarkdown.ast.quarkdown.block.Aligned import eu.iamgio.quarkdown.ast.quarkdown.block.Box import eu.iamgio.quarkdown.ast.quarkdown.block.Clipped import eu.iamgio.quarkdown.ast.quarkdown.block.Container @@ -28,6 +29,8 @@ interface RenderRepresentableVisitor { fun visit(alignment: Table.Alignment): T + fun visit(alignment: Aligned.Alignment): T + fun visit(borderStyle: Container.BorderStyle): T fun visit(stackLayout: Stacked.Layout): T diff --git a/core/src/main/resources/render/theme/global.css b/core/src/main/resources/render/theme/global.css index 40640b6e..705708ae 100644 --- a/core/src/main/resources/render/theme/global.css +++ b/core/src/main/resources/render/theme/global.css @@ -276,8 +276,8 @@ code.focus-lines .hljs-ln-line:not(.focused), } .align-left { - text-align: left; - justify-content: left; + text-align: start; + justify-content: start; align-items: start; } @@ -288,8 +288,8 @@ code.focus-lines .hljs-ln-line:not(.focused), } .align-right { - text-align: right; - justify-content: right; + text-align: end; + justify-content: end; align-items: end; } diff --git a/core/src/test/kotlin/eu/iamgio/quarkdown/HtmlNodeRendererTest.kt b/core/src/test/kotlin/eu/iamgio/quarkdown/HtmlNodeRendererTest.kt index bf9759e9..ea89bdb4 100644 --- a/core/src/test/kotlin/eu/iamgio/quarkdown/HtmlNodeRendererTest.kt +++ b/core/src/test/kotlin/eu/iamgio/quarkdown/HtmlNodeRendererTest.kt @@ -733,9 +733,9 @@ class HtmlNodeRendererTest { val out = readParts("quarkdown/aligned.html") val paragraph = Paragraph(listOf(Text("Foo"), LineBreak, Text("bar"))) - assertEquals(out.next(), Aligned(Aligned.Alignment.LEFT, listOf(paragraph)).render()) + assertEquals(out.next(), Aligned(Aligned.Alignment.START, listOf(paragraph)).render()) assertEquals(out.next(), Aligned(Aligned.Alignment.CENTER, listOf(paragraph)).render()) - assertEquals(out.next(), Aligned(Aligned.Alignment.RIGHT, listOf(paragraph)).render()) + assertEquals(out.next(), Aligned(Aligned.Alignment.END, listOf(paragraph)).render()) } @Test diff --git a/core/src/test/resources/rendering/quarkdown/aligned.html b/core/src/test/resources/rendering/quarkdown/aligned.html index 68e19cf4..0aed3028 100644 --- a/core/src/test/resources/rendering/quarkdown/aligned.html +++ b/core/src/test/resources/rendering/quarkdown/aligned.html @@ -1,4 +1,4 @@ -
+

Foo
@@ -18,7 +18,7 @@ --- -

+

Foo
diff --git a/test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt b/test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt index f9174fc0..76a1fe55 100644 --- a/test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt +++ b/test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt @@ -215,6 +215,18 @@ class FullPipelineTest { it, ) } + + execute( + """ + A + + .align {end} + ### B + C + """.trimIndent(), + ) { + assertEquals("

A

B

C

", it) + } } @Test