Skip to content

Commit

Permalink
Disable code line numbers if requested
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgio committed Jul 22, 2024
1 parent 75ba7ea commit 9c5741c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,13 @@ open class BaseHtmlNodeRenderer(context: Context) : TagNodeRenderer<HtmlTagBuild
tag("code") {
+escapeCriticalContent(node.content)

if (!node.showLineNumbers) {
// Prevents line numbers to show.
attribute("class", "nohljsln") // TODO doesnt work with tag, but does with buildTag
}
classes(
// Sets the code language.
node.language?.let { "language-$it" },
// Disables line numbers.
"nohljsln".takeUnless { node.showLineNumbers },
)
}
.optionalAttribute("class", node.language?.let { "language-$it" })
}

override fun visit(node: HorizontalRule) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,22 @@ class HtmlTagBuilder(
* 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
* @return this for concatenation
* @see css
*/
fun style(init: CssBuilder.() -> Unit) = optionalAttribute("style", css(init).takeUnless { it.isEmpty() })

/**
* Applies a sequence of class names via the `class` attribute to this tag.
* @param classes class names. `null` elements are ignored. The attribute is not applied if all elements are `null`
* @return this for concatenation
*/
fun classes(vararg classes: String?) =
optionalAttribute(
"class",
classes.asSequence().filterNotNull().joinToString(separator = " ").takeIf { it.isNotEmpty() },
)

/**
* @return this builder and its nested content into stringified HTML code.
*/
Expand Down

0 comments on commit 9c5741c

Please sign in to comment.