Skip to content

Commit

Permalink
Improve Stacked HTML rendering code
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgio committed Jun 23, 2024
1 parent 3f0e044 commit ae954f9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,18 @@ class QuarkdownHtmlNodeRenderer(context: Context) : BaseHtmlNodeRenderer(context
override fun visit(node: Aligned) = div("align align-" + node.alignment.name.lowercase(), node.children)

override fun visit(node: Stacked): CharSequence {
return tagBuilder("div", node.children)
.attribute("class", "stack stack-" + node.orientation.asCSS)
.style {
return div("stack stack-${node.orientation.asCSS}") {
+node.children

style {
"justify-content" value node.mainAxisAlignment
"align-items" value node.crossAxisAlignment
"gap" value node.gap
}
.build()
}
}

override fun visit(node: Clipped) = div("clip-" + node.clip.asCSS, node.children)
override fun visit(node: Clipped) = div("clip-${node.clip.asCSS}", node.children)

override fun visit(node: Box) =
div("box") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class FullPipelineTest {
""".trimIndent(),
) {
assertEquals(
"<div class=\"stack stack-horizontal\" style=\"justify-content: flex-start; align-items: center;\">" +
"<div style=\"justify-content: flex-start; align-items: center;\" class=\"stack stack-horizontal\">" +
"<p>Hello 1\nHello 2</p><p>Hello 3</p>" +
"</div>",
it,
Expand All @@ -242,7 +242,7 @@ class FullPipelineTest {
""".trimIndent(),
) {
assertEquals(
"<div class=\"stack stack-vertical\" style=\"justify-content: space-between; align-items: flex-start; gap: 1.0cm;\">" +
"<div style=\"justify-content: space-between; align-items: flex-start; gap: 1.0cm;\" class=\"stack stack-vertical\">" +
"<p>Hello 1</p>" +
"<h2>Hello 2</h2>" +
"<pre><code>Hello 3</code></pre>" +
Expand Down Expand Up @@ -272,11 +272,11 @@ class FullPipelineTest {
""".trimIndent(),
) {
assertEquals(
"<div class=\"stack stack-horizontal\" style=\"justify-content: center; align-items: center; gap: 200.0px;\">" +
"<div class=\"stack stack-vertical\" style=\"justify-content: flex-start; align-items: flex-end;\">" +
"<div style=\"justify-content: center; align-items: center; gap: 200.0px;\" class=\"stack stack-horizontal\">" +
"<div style=\"justify-content: flex-start; align-items: flex-end;\" class=\"stack stack-vertical\">" +
"<h1>Quarkdown</h1><p>A cool language</p>" +
"</div>" +
"<div class=\"stack stack-vertical\" style=\"justify-content: flex-start; align-items: center; gap: 1.0cm;\">" +
"<div style=\"justify-content: flex-start; align-items: center; gap: 1.0cm;\" class=\"stack stack-vertical\">" +
"<div class=\"clip-circle\">" +
"<p><img src=\"img1.png\" alt=\"\" /></p>" +
"</div>" +
Expand Down

0 comments on commit ae954f9

Please sign in to comment.