Skip to content

Commit

Permalink
Add .whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgio committed Jul 7, 2024
1 parent 48d2753 commit 99cb8f1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package eu.iamgio.quarkdown.ast.quarkdown

import eu.iamgio.quarkdown.ast.Node
import eu.iamgio.quarkdown.document.page.Size
import eu.iamgio.quarkdown.visitor.node.NodeVisitor

/**
* An empty square in a document that adds whitespace to the layout.
*/
data class Whitespace(val width: Size?, val height: Size?) : Node {
override fun <T> accept(visitor: NodeVisitor<T>): T = visitor.visit(this)
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import eu.iamgio.quarkdown.ast.quarkdown.PageMarginContentInitializer
import eu.iamgio.quarkdown.ast.quarkdown.SlidesConfigurationInitializer
import eu.iamgio.quarkdown.ast.quarkdown.Stacked
import eu.iamgio.quarkdown.ast.quarkdown.TextTransform
import eu.iamgio.quarkdown.ast.quarkdown.Whitespace
import eu.iamgio.quarkdown.context.Context
import eu.iamgio.quarkdown.context.resolveOrFallback
import eu.iamgio.quarkdown.rendering.UnsupportedRenderException
Expand Down Expand Up @@ -240,6 +241,8 @@ open class BaseHtmlNodeRenderer(context: Context) : TagNodeRenderer<HtmlTagBuild

override fun visit(node: Box): CharSequence = throw UnsupportedRenderException(node)

override fun visit(node: Whitespace): CharSequence = throw UnsupportedRenderException(node)

override fun visit(node: PageMarginContentInitializer): CharSequence = throw UnsupportedRenderException(node)

override fun visit(node: PageCounterInitializer): CharSequence = throw UnsupportedRenderException(node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import eu.iamgio.quarkdown.ast.quarkdown.PageMarginContentInitializer
import eu.iamgio.quarkdown.ast.quarkdown.SlidesConfigurationInitializer
import eu.iamgio.quarkdown.ast.quarkdown.Stacked
import eu.iamgio.quarkdown.ast.quarkdown.TextTransform
import eu.iamgio.quarkdown.ast.quarkdown.Whitespace
import eu.iamgio.quarkdown.context.Context
import eu.iamgio.quarkdown.document.DocumentType
import eu.iamgio.quarkdown.rendering.tag.buildTag
Expand Down Expand Up @@ -101,6 +102,14 @@ class QuarkdownHtmlNodeRenderer(context: Context) : BaseHtmlNodeRenderer(context
}
}

override fun visit(node: Whitespace) =
buildTag("span") {
style {
"width" value node.width
"height" value node.height
}
}

// Inline

// Math is processed by the MathJax library which requires text delimiters instead of tags.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import eu.iamgio.quarkdown.ast.quarkdown.PageMarginContentInitializer
import eu.iamgio.quarkdown.ast.quarkdown.SlidesConfigurationInitializer
import eu.iamgio.quarkdown.ast.quarkdown.Stacked
import eu.iamgio.quarkdown.ast.quarkdown.TextTransform
import eu.iamgio.quarkdown.ast.quarkdown.Whitespace

/**
* A visitor for [eu.iamgio.quarkdown.ast.Node]s.
Expand Down Expand Up @@ -127,6 +128,8 @@ interface NodeVisitor<T> {

fun visit(node: Box): T

fun visit(node: Whitespace): T

// Quarkdown inline

fun visit(node: MathSpan): T
Expand Down
13 changes: 13 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 @@ -6,6 +6,7 @@ import eu.iamgio.quarkdown.ast.quarkdown.Aligned
import eu.iamgio.quarkdown.ast.quarkdown.Box
import eu.iamgio.quarkdown.ast.quarkdown.Clipped
import eu.iamgio.quarkdown.ast.quarkdown.Stacked
import eu.iamgio.quarkdown.ast.quarkdown.Whitespace
import eu.iamgio.quarkdown.context.Context
import eu.iamgio.quarkdown.document.page.Size
import eu.iamgio.quarkdown.function.reflect.Injected
Expand All @@ -27,6 +28,7 @@ val Layout: Module =
::stack,
::row,
::column,
::whitespace,
::clip,
::box,
::table,
Expand Down Expand Up @@ -102,6 +104,17 @@ fun column(
body: MarkdownContent,
) = stack(Stacked.Orientation.VERTICAL, mainAxisAlignment, crossAxisAlignment, gap, body)

/**
* An empty square that adds whitespace to the layout.
* @param width width of the square. If unset, it defaults to zero
* @param height height of the square. If unset, it defaults to zero
* @return the new whitespace node
*/
fun whitespace(
width: Size? = null,
height: Size? = null,
) = Whitespace(width, height).wrappedAsValue()

/**
* Applies a clipping path to its content.
* @param clip clip type to apply
Expand Down

0 comments on commit 99cb8f1

Please sign in to comment.