Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ElementContainer.toString #672

Merged
merged 1 commit into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}

}
Loading