Skip to content

Commit

Permalink
Make HorizontalRule, Comment, Newline and BlockText data objects
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgio committed Sep 17, 2024
1 parent c1b9a35 commit edaafcc
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import eu.iamgio.quarkdown.ast.Node
import eu.iamgio.quarkdown.visitor.node.NodeVisitor

/**
* Anything else (should not happen).
* Any unknown node type (should not happen).
*/
class BlockText : Node {
data object BlockText : Node {
override fun <T> accept(visitor: NodeVisitor<T>) = visitor.visit(this)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import eu.iamgio.quarkdown.visitor.node.NodeVisitor
/**
* A horizontal line (thematic break).
*/
class HorizontalRule : Node {
override fun toString() = "HorizontalRule"

data object HorizontalRule : Node {
override fun <T> accept(visitor: NodeVisitor<T>) = visitor.visit(this)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import eu.iamgio.quarkdown.visitor.node.NodeVisitor
/**
* A blank line.
*/
class Newline : Node {
override fun toString() = "Newline"

data object Newline : Node {
override fun <T> accept(visitor: NodeVisitor<T>) = visitor.visit(this)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import eu.iamgio.quarkdown.visitor.node.NodeVisitor
/**
* A comment whose content is ignored.
*/
class Comment : Node {
override fun toString() = "Comment"

data object Comment : Node {
override fun <T> accept(visitor: NodeVisitor<T>) = visitor.visit(this)
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ abstract class NodeOutputValueVisitor : OutputValueVisitor<Node> {

override fun visit(value: NodeValue) = value.unwrappedValue

override fun visit(value: VoidValue) = BlockText()
override fun visit(value: VoidValue) = BlockText

// Dynamic output (e.g. produced by the stdlib function `.function`) is treated:
// - If it is a suitable output value: its content is visited again with this visitor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class BlockTokenParser(private val context: MutableContext) : BlockTokenVisitor<
.tokenizeAndParse()

override fun visit(token: NewlineToken): Node {
return Newline()
return Newline
}

override fun visit(token: BlockCodeToken): Node {
Expand Down Expand Up @@ -110,7 +110,7 @@ class BlockTokenParser(private val context: MutableContext) : BlockTokenVisitor<
}

override fun visit(token: HorizontalRuleToken): Node {
return HorizontalRule()
return HorizontalRule
}

/**
Expand Down Expand Up @@ -382,7 +382,7 @@ class BlockTokenParser(private val context: MutableContext) : BlockTokenVisitor<
}

override fun visit(token: BlockTextToken): Node {
return BlockText()
return BlockText
}

override fun visit(token: PageBreakToken): Node {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class InlineTokenParser(private val context: MutableContext) : InlineTokenVisito

override fun visit(token: CommentToken): Node {
// Content is ignored.
return Comment()
return Comment
}

override fun visit(token: LineBreakToken): Node {
Expand Down
14 changes: 7 additions & 7 deletions core/src/test/kotlin/eu/iamgio/quarkdown/HtmlNodeRendererTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class HtmlNodeRendererTest {
// Inline
@Test
fun comment() {
assertEquals("", Comment().render())
assertEquals("", Comment.render())
}

@Test
Expand Down Expand Up @@ -391,7 +391,7 @@ class HtmlNodeRendererTest {

@Test
fun horizontalRule() {
assertEquals("<hr />", HorizontalRule().render())
assertEquals("<hr />", HorizontalRule.render())
}

@Test
Expand Down Expand Up @@ -443,23 +443,23 @@ class HtmlNodeRendererTest {
children =
listOf(
Paragraph(listOf(Text("A1"))),
HorizontalRule(),
HorizontalRule,
Paragraph(listOf(Text("A2"))),
),
),
BaseListItem(
children =
listOf(
Paragraph(listOf(Text("B1"))),
HorizontalRule(),
HorizontalRule,
Paragraph(listOf(Text("B2"))),
),
),
BaseListItem(
children =
listOf(
Paragraph(listOf(Text("C1"))),
HorizontalRule(),
HorizontalRule,
Paragraph(listOf(Text("C2"))),
),
),
Expand All @@ -468,15 +468,15 @@ class HtmlNodeRendererTest {
children =
listOf(
Paragraph(listOf(Text("D1"))),
HorizontalRule(),
HorizontalRule,
Paragraph(listOf(Text("D2"))),
),
),
TaskListItem(
isChecked = true,
listOf(
Paragraph(listOf(Text("E1"))),
HorizontalRule(),
HorizontalRule,
Paragraph(listOf(Text("E2"))),
),
),
Expand Down
2 changes: 1 addition & 1 deletion stdlib/src/main/kotlin/eu/iamgio/quarkdown/stdlib/Flow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,4 @@ fun let(
* in case the visible output does not match the expected one.
* @return an invisible mock node
*/
fun node(): NodeValue = BlockText().wrappedAsValue()
fun node(): NodeValue = BlockText.wrappedAsValue()
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ class FullPipelineTest {
"<header><h4>Error: sum</h4></header>" +
"<div class=\"box-content\"><p>" +
"Cannot call function sum" +
"<span class=\"inline-collapse\" data-full-text=\"(Number a, Number b)\"" +
"<span class=\"inline-collapse\" data-full-text=\"(Number a, Number b)\" " +
"data-collapsed-text=\"(...)\" data-collapsed=\"false\">" +
"(Number a, Number b)" +
"</span>" +
Expand Down

0 comments on commit edaafcc

Please sign in to comment.