diff --git a/core/src/main/kotlin/eu/iamgio/quarkdown/context/ContextOptions.kt b/core/src/main/kotlin/eu/iamgio/quarkdown/context/ContextOptions.kt index ce4955a6..d399c11c 100644 --- a/core/src/main/kotlin/eu/iamgio/quarkdown/context/ContextOptions.kt +++ b/core/src/main/kotlin/eu/iamgio/quarkdown/context/ContextOptions.kt @@ -11,7 +11,7 @@ interface ContextOptions : MediaStorageOptions { /** * When a [Heading] node has a depth equals or less than this value, a page break is forced. */ - val autoPageBreakHeadingDepth: Int + val autoPageBreakHeadingMaxDepth: Int /** * Whether automatic identifiers should be generated for elements @@ -24,15 +24,15 @@ interface ContextOptions : MediaStorageOptions { /** * @return whether the [heading] node should force a page break - * @see ContextOptions.autoPageBreakHeadingDepth + * @see ContextOptions.autoPageBreakHeadingMaxDepth */ -fun Context.shouldAutoPageBreak(heading: Heading) = !heading.isMarker && heading.depth <= this.options.autoPageBreakHeadingDepth +fun Context.shouldAutoPageBreak(heading: Heading) = !heading.isMarker && heading.depth <= this.options.autoPageBreakHeadingMaxDepth /** * Mutable [ContextOptions] implementation. */ data class MutableContextOptions( - override var autoPageBreakHeadingDepth: Int = 1, + override var autoPageBreakHeadingMaxDepth: Int = 1, override var enableAutomaticIdentifiers: Boolean = true, override var enableRemoteMediaStorage: Boolean = false, override var enableLocalMediaStorage: Boolean = false, diff --git a/core/src/test/kotlin/eu/iamgio/quarkdown/HtmlNodeRendererTest.kt b/core/src/test/kotlin/eu/iamgio/quarkdown/HtmlNodeRendererTest.kt index 478ee6eb..c56d7d16 100644 --- a/core/src/test/kotlin/eu/iamgio/quarkdown/HtmlNodeRendererTest.kt +++ b/core/src/test/kotlin/eu/iamgio/quarkdown/HtmlNodeRendererTest.kt @@ -408,7 +408,7 @@ class HtmlNodeRendererTest { val noIdNoPageBreak = MutableContext( QuarkdownFlavor, - options = MutableContextOptions(autoPageBreakHeadingDepth = 0, enableAutomaticIdentifiers = false), + options = MutableContextOptions(autoPageBreakHeadingMaxDepth = 0, enableAutomaticIdentifiers = false), ) assertEquals(out.next(), Heading(1, listOf(Text("Foo bar"))).render(noIdNoPageBreak)) @@ -421,7 +421,7 @@ class HtmlNodeRendererTest { val idNoPageBreak = MutableContext( QuarkdownFlavor, - options = MutableContextOptions(autoPageBreakHeadingDepth = 0), + options = MutableContextOptions(autoPageBreakHeadingMaxDepth = 0), ) assertEquals(out.next(), Heading(1, listOf(Text("Foo bar"))).render(idNoPageBreak)) @@ -430,7 +430,7 @@ class HtmlNodeRendererTest { // Automatic ID, force page break on depth <= 2 val autoPageBreak = - MutableContext(QuarkdownFlavor, options = MutableContextOptions(autoPageBreakHeadingDepth = 2)) + MutableContext(QuarkdownFlavor, options = MutableContextOptions(autoPageBreakHeadingMaxDepth = 2)) assertEquals(out.next(), Heading(1, listOf(Text("Foo bar"))).render(autoPageBreak)) assertEquals(out.next(), Heading(2, listOf(Text("Foo bar"))).render(autoPageBreak)) diff --git a/demo/demo.qmd b/demo/demo.qmd index dd5d93d2..055296c6 100644 --- a/demo/demo.qmd +++ b/demo/demo.qmd @@ -3,7 +3,7 @@ .doctype {slides} .doclang {English} .theme {darko} layout:{minimal} -.autopagebreak depth:{2} +.autopagebreak maxdepth:{2} .footer .docauthor diff --git a/stdlib/src/main/kotlin/eu/iamgio/quarkdown/stdlib/Document.kt b/stdlib/src/main/kotlin/eu/iamgio/quarkdown/stdlib/Document.kt index 74f2a8df..87f61ee2 100644 --- a/stdlib/src/main/kotlin/eu/iamgio/quarkdown/stdlib/Document.kt +++ b/stdlib/src/main/kotlin/eu/iamgio/quarkdown/stdlib/Document.kt @@ -260,22 +260,22 @@ fun totalPages() = PageCounter(PageCounter.Target.TOTAL).wrappedAsValue() /** * Sets a new automatic page break threshold when a heading is found: - * if a heading's depth value (the amount of leading `#`s) is equals or less than [depth], + * if a heading's depth value (the amount of leading `#`s) is equals or less than [maxDepth], * a page break is forced before the heading. - * @param depth heading depth to force page breaks for (positive only). - * @throws IllegalArgumentException if [depth] is a negative value + * @param maxDepth heading depth to force page breaks for (positive only). + * @throws IllegalArgumentException if [maxDepth] is a negative value * @see disableAutoPageBreak */ @Name("autopagebreak") fun autoPageBreak( @Injected context: MutableContext, - depth: Int, + @Name("maxdepth") maxDepth: Int, ): VoidValue { - if (depth < 0) { + if (maxDepth < 0) { throw IllegalArgumentException("Heading depth cannot be negative.") } - context.options.autoPageBreakHeadingDepth = depth + context.options.autoPageBreakHeadingMaxDepth = maxDepth return VoidValue } diff --git a/test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt b/test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt index 7cc80fad..f0a33f70 100644 --- a/test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt +++ b/test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt @@ -104,7 +104,7 @@ class FullPipelineTest { .theme {darko} layout:{minimal} .pageformat {A3} orientation:{landscape} margin:{3cm 2px} .slides transition:{zoom} speed:{fast} - .autopagebreak depth:{3} + .autopagebreak maxdepth:{3} """.trimIndent(), ) { assertEquals("My Quarkdown document", documentInfo.name) @@ -212,6 +212,52 @@ class FullPipelineTest { } } + @Test + fun headings() { + execute("# Title") { + assertEquals("