Skip to content

Commit

Permalink
Add HtmlTagBuilder#style
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgio committed Jun 23, 2024
1 parent 90aca9e commit 3f0e044
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ class HtmlTagBuilder(
*/
fun void(isVoid: Boolean) = apply { this.isVoid = isVoid }

/**
* Applies a CSS style via the `style` attribute to this tag.
* The attribute is _not_ added if the generated CSS string is empty.
* @param init CSS builder initialization
* @see css
*/
fun style(init: CssBuilder.() -> Unit) = optionalAttribute("style", css(init).takeUnless { it.isEmpty() })

/**
* @return this builder and its nested content into stringified HTML code.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,11 @@ class QuarkdownHtmlNodeRenderer(context: Context) : BaseHtmlNodeRenderer(context
override fun visit(node: Stacked): CharSequence {
return tagBuilder("div", node.children)
.attribute("class", "stack stack-" + node.orientation.asCSS)
.attribute(
"style",
css {
"justify-content" value node.mainAxisAlignment
"align-items" value node.crossAxisAlignment
"gap" value node.gap
},
)
.style {
"justify-content" value node.mainAxisAlignment
"align-items" value node.crossAxisAlignment
"gap" value node.gap
}
.build()
}

Expand All @@ -85,14 +82,11 @@ class QuarkdownHtmlNodeRenderer(context: Context) : BaseHtmlNodeRenderer(context
+node.children

// Box style.
optionalAttribute(
"style",
css {
"padding" value node.padding
"background-color" value node.backgroundColor
"color" value node.foregroundColor
}.takeUnless { it.isEmpty() },
)
style {
"padding" value node.padding
"background-color" value node.backgroundColor
"color" value node.foregroundColor
}
}

// Inline
Expand Down

0 comments on commit 3f0e044

Please sign in to comment.