From c77d99e5933a08047ffd7528df4d9693f16c8117 Mon Sep 17 00:00:00 2001 From: Giorgio Garofalo Date: Mon, 26 Aug 2024 17:22:52 +0200 Subject: [PATCH] Add `overline`, `underoverline` and `all` text decoration options --- .../quarkdown/ast/quarkdown/inline/TextTransform.kt | 3 +++ .../rendering/html/CssRepresentableVisitor.kt | 2 ++ .../eu/iamgio/quarkdown/HtmlNodeRendererTest.kt | 13 +++++++++++-- .../rendering/quarkdown/texttransform.html | 12 +++++++++--- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/core/src/main/kotlin/eu/iamgio/quarkdown/ast/quarkdown/inline/TextTransform.kt b/core/src/main/kotlin/eu/iamgio/quarkdown/ast/quarkdown/inline/TextTransform.kt index 176e4d0e..156b1b9b 100644 --- a/core/src/main/kotlin/eu/iamgio/quarkdown/ast/quarkdown/inline/TextTransform.kt +++ b/core/src/main/kotlin/eu/iamgio/quarkdown/ast/quarkdown/inline/TextTransform.kt @@ -59,7 +59,10 @@ class TextTransformData( enum class Decoration : RenderRepresentable { NONE, UNDERLINE, + OVERLINE, + UNDEROVERLINE, STRIKETHROUGH, + ALL, ; override fun accept(visitor: RenderRepresentableVisitor): T = visitor.visit(this) diff --git a/core/src/main/kotlin/eu/iamgio/quarkdown/rendering/html/CssRepresentableVisitor.kt b/core/src/main/kotlin/eu/iamgio/quarkdown/rendering/html/CssRepresentableVisitor.kt index ad8c327f..154e0db3 100644 --- a/core/src/main/kotlin/eu/iamgio/quarkdown/rendering/html/CssRepresentableVisitor.kt +++ b/core/src/main/kotlin/eu/iamgio/quarkdown/rendering/html/CssRepresentableVisitor.kt @@ -81,6 +81,8 @@ class CssRepresentableVisitor : RenderRepresentableVisitor { override fun visit(decoration: TextTransformData.Decoration) = when (decoration) { TextTransformData.Decoration.STRIKETHROUGH -> "line-through" + TextTransformData.Decoration.UNDEROVERLINE -> "underline overline" + TextTransformData.Decoration.ALL -> "underline overline line-through" else -> decoration.kebabCaseName } diff --git a/core/src/test/kotlin/eu/iamgio/quarkdown/HtmlNodeRendererTest.kt b/core/src/test/kotlin/eu/iamgio/quarkdown/HtmlNodeRendererTest.kt index 1c2584b0..59d638c5 100644 --- a/core/src/test/kotlin/eu/iamgio/quarkdown/HtmlNodeRendererTest.kt +++ b/core/src/test/kotlin/eu/iamgio/quarkdown/HtmlNodeRendererTest.kt @@ -726,7 +726,7 @@ class HtmlNodeRendererTest { TextTransformData( size = TextTransformData.Size.LARGE, style = TextTransformData.Style.ITALIC, - decoration = TextTransformData.Decoration.UNDERLINE, + decoration = TextTransformData.Decoration.STRIKETHROUGH, ), listOf(Text("Foo")), ).render(), @@ -738,7 +738,7 @@ class HtmlNodeRendererTest { TextTransformData( size = TextTransformData.Size.TINY, weight = TextTransformData.Weight.BOLD, - decoration = TextTransformData.Decoration.STRIKETHROUGH, + decoration = TextTransformData.Decoration.UNDEROVERLINE, variant = TextTransformData.Variant.SMALL_CAPS, ), listOf(Emphasis(listOf(Text("Foo"))), Text("bar")), @@ -750,10 +750,19 @@ class HtmlNodeRendererTest { TextTransform( TextTransformData( weight = TextTransformData.Weight.BOLD, + decoration = TextTransformData.Decoration.ALL, color = Color(255, 0, 0), ), listOf(Text("Foo")), ).render(), ) + + assertEquals( + out.next(), + TextTransform( + TextTransformData(), + listOf(Text("Foo")), + ).render(), + ) } } diff --git a/core/src/test/resources/rendering/quarkdown/texttransform.html b/core/src/test/resources/rendering/quarkdown/texttransform.html index 83169957..263d1045 100644 --- a/core/src/test/resources/rendering/quarkdown/texttransform.html +++ b/core/src/test/resources/rendering/quarkdown/texttransform.html @@ -1,10 +1,10 @@ - + Foo --- - + Foo @@ -13,6 +13,12 @@ --- - + + Foo + + +--- + + Foo \ No newline at end of file