Skip to content

Commit

Permalink
Add alignment parameter to .container
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgio committed Nov 23, 2024
1 parent 52fbb24 commit ff24394
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import eu.iamgio.quarkdown.visitor.node.NodeVisitor
* @param borderStyle border style
* @param padding whitespace around the content
* @param cornerRadius border radius of the container
* @param alignment alignment of the content
*/
class Container(
val foregroundColor: Color? = null,
Expand All @@ -26,6 +27,7 @@ class Container(
val borderStyle: BorderStyle? = null,
val padding: Sizes? = null,
val cornerRadius: Sizes? = null,
val alignment: Aligned.Alignment? = null,
override val children: List<Node>,
) : NestableNode {
override fun <T> accept(visitor: NodeVisitor<T>): T = visitor.visit(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ class QuarkdownHtmlNodeRenderer(context: Context) : BaseHtmlNodeRenderer(context
// No border style.
else -> null
}

"text-align" value node.alignment
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ class HtmlNodeRendererTest {
borderWidth = Sizes(all = 1.0.cm),
padding = Sizes(2.0.inch, 3.0.inch, 4.0.inch, 5.0.inch),
cornerRadius = Sizes(all = 6.0.px),
alignment = Aligned.Alignment.CENTER,
children = children,
).render(),
)
Expand All @@ -772,6 +773,7 @@ class HtmlNodeRendererTest {
Container(
borderColor = Color(30, 20, 10),
borderStyle = Container.BorderStyle.DOTTED,
alignment = Aligned.Alignment.END,
children = children,
).render(),
)
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/resources/rendering/quarkdown/container.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

---

<div style="padding: 2.0in 3.0in 4.0in 5.0in; border-color: rgba(30, 20, 10, 1.0); border-width: 1.0cm 1.0cm 1.0cm 1.0cm; border-radius: 6.0px 6.0px 6.0px 6.0px; border-style: solid;" class="container">
<div style="padding: 2.0in 3.0in 4.0in 5.0in; border-color: rgba(30, 20, 10, 1.0); border-width: 1.0cm 1.0cm 1.0cm 1.0cm; border-radius: 6.0px 6.0px 6.0px 6.0px; border-style: solid; text-align: center;" class="container">
<p>
Foo bar
</p>
Expand All @@ -50,7 +50,7 @@

---

<div style="border-color: rgba(30, 20, 10, 1.0); border-style: dotted;" class="container">
<div style="border-color: rgba(30, 20, 10, 1.0); border-style: dotted; text-align: end;" class="container">
<p>
Foo bar
</p>
Expand Down
3 changes: 3 additions & 0 deletions stdlib/src/main/kotlin/eu/iamgio/quarkdown/stdlib/Layout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ val Layout: Module =
* @param borderStyle border style. Normal (solid) if unset and [borderColor] or [borderWidth] is set
* @param padding whitespace around the content. None if unset
* @param cornerRadius corner (and border) radius. None if unset
* @param alignment alignment of the content. Default if unset
* @param body content to group
* @return the new container node
*/
Expand All @@ -65,6 +66,7 @@ fun container(
@Name("borderstyle") borderStyle: Container.BorderStyle? = null,
@Name("padding") padding: Sizes? = null,
@Name("radius") cornerRadius: Sizes? = null,
alignment: Aligned.Alignment? = null,
body: MarkdownContent,
) = Container(
foregroundColor,
Expand All @@ -74,6 +76,7 @@ fun container(
borderStyle,
padding,
cornerRadius,
alignment,
body.children,
).wrappedAsValue()

Expand Down

0 comments on commit ff24394

Please sign in to comment.