Skip to content

Commit

Permalink
Rename .align's left/right to start/end
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgio committed Oct 8, 2024
1 parent 5081c9e commit d4b2ee7
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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 <T> accept(visitor: RenderRepresentableVisitor<T>): T = visitor.visit(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,6 +36,8 @@ class CssRepresentableVisitor : RenderRepresentableVisitor<String> {

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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,6 +29,8 @@ interface RenderRepresentableVisitor<T> {

fun visit(alignment: Table.Alignment): T

fun visit(alignment: Aligned.Alignment): T

fun visit(borderStyle: Container.BorderStyle): T

fun visit(stackLayout: Stacked.Layout): T
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/resources/render/theme/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/resources/rendering/quarkdown/aligned.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="align align-left">
<div class="align align-start">
<p>
Foo
<br />
Expand All @@ -18,7 +18,7 @@

---

<div class="align align-right">
<div class="align align-end">
<p>
Foo
<br />
Expand Down
12 changes: 12 additions & 0 deletions test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ class FullPipelineTest {
it,
)
}

execute(
"""
A
.align {end}
### B
C
""".trimIndent(),
) {
assertEquals("<p>A</p><div class=\"align align-end\"><h3>B</h3></div><p>C</p>", it)
}
}

@Test
Expand Down

0 comments on commit d4b2ee7

Please sign in to comment.