Skip to content

Commit

Permalink
Avoid .stripMargin when rendering documentation from example modules (
Browse files Browse the repository at this point in the history
#4544)

Since we use Scala string intrpolation as a low cost template engine,
we need to avoid `.stripMargin`, as it may over-eager strip margin
symbols
from the interpolated variables.

Fix #4542

Pull request: #4544
  • Loading branch information
lefou authored Feb 12, 2025
1 parent d8cf62a commit f6d3dad
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions example/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,13 @@ object `package` extends RootModule with Module {
.filter(_._2.nonEmpty)
.map {
case (s"see:$path", txt) =>
// avoid .stripMargin, as the embedded content may contain the margin symbol
s"""
|.$path ({mill-example-url}/$examplePath/$path[browse])
|[source,scala,subs="attributes,verbatim"]
|----
|$txt
|----""".stripMargin
.$path ({mill-example-url}/$examplePath/$path[browse])
[source,scala,subs="attributes,verbatim"]
----
$txt
----"""
case ("scala", txt) =>
val title =
if (seenCode) ""
Expand All @@ -268,21 +269,23 @@ object `package` extends RootModule with Module {
s".build.mill ($download, $browse)"
}
seenCode = true
// avoid .stripMargin, as the embedded content may contain the margin symbol
s"""
|$title
|[source,scala,subs="attributes,verbatim"]
|----
|
|$txt
|----
|""".stripMargin
$title
[source,scala,subs="attributes,verbatim"]
----

$txt
----
"""
case ("comment", txt) => txt + "\n"
case ("example", txt) =>
// avoid .stripMargin, as the embedded content may contain the margin symbol
s"""
|[source,bash,subs="attributes,verbatim"]
|----
|$txt
|----""".stripMargin
[source,bash,subs="attributes,verbatim"]
----
$txt
----"""
}
.mkString("\n")
)
Expand Down

0 comments on commit f6d3dad

Please sign in to comment.