Skip to content

Commit

Permalink
fix ElementContainer.toString
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshalm committed Jan 1, 2025
1 parent 8778fc8 commit 5d51eb8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion core/shared/src/main/scala/laika/ast/containers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package laika.ast

import laika.api.Renderer
import laika.format.AST
import cats.syntax.all.*

/** A generic container.
* Usually not mixed in directly, instead one of the sub-traits
Expand Down Expand Up @@ -163,5 +164,8 @@ trait BlockContainerCompanion extends SpanContainerCompanion {

private[ast] object FormattedElementString {
private lazy val renderer: Renderer = Renderer.of(AST).build.skipRewritePhase
def render(elem: Element): String = "\n" + renderer.render(elem) + "\n"

def render(elem: Element): String =
renderer.render(elem).leftMap(err => s"<${err.message}>").merge

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package laika.ast

import munit.FunSuite

class ElementContainerToStringSpec extends FunSuite {

test("toString for ElementContainer") {
val element = Paragraph(Text("some"), Emphasized("em"), Text("text"))
val expected = """Paragraph - Spans: 3
|. Text - 'some'
|. Emphasized - Spans: 1
|. . Text - 'em'
|. Text - 'text'""".stripMargin
assertEquals(element.toString, expected)
}

}

0 comments on commit 5d51eb8

Please sign in to comment.