Skip to content

Commit

Permalink
Workaround for multi-line outputs.
Browse files Browse the repository at this point in the history
It seems that mdoc assumes a type name to be stringified into a
single line but that is wrong for RefinedType.

May be we should fix this line:
https://github.com/scalameta/mdoc/blob/69fea55c23477fbb6aed94e39b54b31efa56cf24/cli/src/main/scala/mdoc/internal/markdown/ReplVariablePrinter.scala#L25
  • Loading branch information
tarao committed Nov 15, 2023
1 parent 726fb49 commit e1246f0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
site.MultilineOutputModifier
32 changes: 32 additions & 0 deletions site/src/main/scala/site/MultilineOutputModifier.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package site

import mdoc.{PostModifier, PostModifierContext}

class MultilineOutputModifier extends PostModifier {
val name = "mline"

def process(ctx: PostModifierContext): String = {
val code = ctx.variables.map { v =>
val s = v.toString
(s, linesAsComment(s))
}.foldLeft(ctx.outputCode) { case (code, (from, to)) =>
code.replace(from, to)
}

s"""```scala
|${code}
|```
|""".stripMargin
}

private def linesAsComment(lines: String): String =
lines.split("\n").map(lineAsComment(_)).mkString("\n")

private def lineAsComment(line: String): String =
if (line.isEmpty())
line
else if (line.startsWith("//"))
line
else
"// " + line
}

0 comments on commit e1246f0

Please sign in to comment.