Skip to content

Commit

Permalink
Fix code span tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgio committed Aug 10, 2024
1 parent 2945869 commit 45899f6
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class QuarkdownHtmlNodeRenderer(context: Context) : BaseHtmlNodeRenderer(context

// The code is wrapped to allow additional content.
return buildTag("span") {
`class`("codespan-content-wrapper")
`class`("codespan-content")

+codeTag

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/render/theme/color/darko.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ h1, h2, h3, h4, h5, h6 {
color: inherit;
}

.codespan-content-wrapper:not(.box .codespan-content-wrapper) {
.codespan-content:not(.box .codespan-content) {
background-color: var(--primary);
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/render/theme/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ a {
clip-path: circle();
}

.codespan-content-wrapper {
.codespan-content {
display: inline-flex;
align-items: center;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/render/theme/layout/minimal.css
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ p code {
font-size: 1.2em;
}

.codespan-content-wrapper {
.codespan-content {
padding: 0.1em 0.6em;
border-radius: 8px;
}
Expand Down
18 changes: 12 additions & 6 deletions core/src/test/kotlin/eu/iamgio/quarkdown/HtmlNodeRendererTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,21 @@ class HtmlNodeRendererTest {
fun codeSpan() {
val out = readParts("inline/codespan.html")

assertEquals(out.next(), CodeSpan("Foo bar").render())
assertEquals(out.next(), CodeSpan("<a href=\"#\">").render())
assertEquals(
out.next(),
// The Quarkdown rendering wraps the content in a span which allows additional content, such as color.
val base = MutableContext(BaseMarkdownFlavor)
val quarkdown = MutableContext(QuarkdownFlavor)

val spanWithColor =
CodeSpan(
"#FFFF00",
CodeSpan.ColorContent(Color.fromHex("#FFFF00")!!),
).render(),
)
)

assertEquals(out.next(), CodeSpan("Foo bar").render(base))
assertEquals(out.next(), CodeSpan("<a href=\"#\">").render(base))
assertEquals(out.next(), spanWithColor.render(quarkdown))
assertEquals(out.next(), spanWithColor.render(base))
assertEquals(out.next(), CodeSpan("Foo bar").render(quarkdown))
}

@Test
Expand Down
16 changes: 15 additions & 1 deletion core/src/test/resources/rendering/inline/codespan.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,24 @@

---

<span class="codespan-content-wrapper">
<span class="codespan-content">
<code>
#FFFF00
</code>
<span style="background-color: rgba(255, 255, 0, 1.0);" class="color-preview">
</span>
</span>

---

<code>
#FFFF00
</code>

---

<span class="codespan-content">
<code>
Foo bar
</code>
</span>
24 changes: 19 additions & 5 deletions test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,21 @@ class FullPipelineTest {
@Test
fun code() {
execute("`println(\"Hello, world!\")`") {
assertEquals("<p><code>println(&quot;Hello, world!&quot;)</code></p>", it)
assertEquals("<p><span class=\"codespan-content\"><code>println(&quot;Hello, world!&quot;)</code></span></p>", it)
assertFalse(attributes.hasCode)
}

// Color preview
execute("`#FF0000`") {
assertEquals(
"<p>" +
"<span class=\"codespan-content\">" +
"<code>#FF0000</code>" +
"<span style=\"background-color: rgba(255, 0, 0, 1.0);\" class=\"color-preview\"></span>" +
"</span>" +
"</p>",
it,
)
assertFalse(attributes.hasCode)
}

Expand Down Expand Up @@ -290,12 +304,12 @@ class FullPipelineTest {
)
}

execute(".function {hello}\n `Hello`!\n\n.hello") {
assertEquals("<p><code>Hello</code>!</p>", it)
execute(".function {hello}\n *Hello*!\n\n.hello") {
assertEquals("<p><em>Hello</em>!</p>", it)
}

execute(".function {hello}\n target:\n `Hello` .target!\n\n.hello {world}") {
assertEquals("<p><code>Hello</code> world!</p>", it)
execute(".function {hello}\n target:\n **Hello** .target!\n\n.hello {world}") {
assertEquals("<p><strong>Hello</strong> world!</p>", it)
}

assertFailsWith<InvalidArgumentCountException> {
Expand Down

0 comments on commit 45899f6

Please sign in to comment.