Skip to content

Commit b917703

Browse files
committed
[base-2] Correctly render the doc-root-content subheader
1 parent fd4ee29 commit b917703

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ lazy val sharedSettings = Seq(
3636
case "2.12" | "2.13" => Seq(
3737
"-doc-title", name.value,
3838
"-doc-version", (if ("-SNAPSHOT" == version.value) {"SNAPSHOT"} else {version.value}),
39-
"-doc-root-content", ((Compile / scalaSource).value / "rootdoc.md").toString,
39+
"-doc-root-content", ((Compile / docRootContentToWikidoc).value).toString,
4040
"-doc-source-url", s"https://github.com/${githubId}/tree/${if (version.value.endsWith("-SNAPSHOT")) {git.gitHeadCommit.value.get} else {version.value}}€{FILE_PATH}.scala",
4141
"-implicits",
4242
"-groups",

project/DocRootContentToWikidoc.scala

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package name.rayrobdod.stringContextParserCombinator.build
2+
3+
import sbt._
4+
import sbt.Keys._
5+
6+
object DocRootContentToWikidoc extends AutoPlugin {
7+
override def requires = sbt.plugins.JvmPlugin
8+
override def trigger = allRequirements
9+
10+
object autoImport {
11+
val markdownSource = settingKey[File]("")
12+
val docRootContentToWikidoc = taskKey[File]("Convert the doc-root-content file from scala-3's markdown to scala-2's wikidoc")
13+
}
14+
import autoImport._
15+
16+
override val globalSettings = Seq(
17+
)
18+
19+
private def unscopedSettings = Seq(
20+
)
21+
22+
object HeaderLine {
23+
def unapply(s:String): Option[(String, Int)] = {
24+
val (hashes, rest) = s.span(_ == '#')
25+
if (hashes.size != 0 && rest.head == ' ') {
26+
Some((rest.tail, hashes.size))
27+
} else {
28+
None
29+
}
30+
}
31+
}
32+
33+
private def perScopeSettings(config:sbt.librarymanagement.Configuration) = Seq(
34+
config / docRootContentToWikidoc / target := (target.value / s"${config.name}-rootdoc.wikidoc"),
35+
config / docRootContentToWikidoc / markdownSource := ((config / scalaSource).value / "rootdoc.md"),
36+
config / docRootContentToWikidoc := {
37+
val in = (config / docRootContentToWikidoc / markdownSource).value
38+
val out = (config / docRootContentToWikidoc / target).value
39+
40+
if (in.exists()) {
41+
sbt.io.IO.writeLines(
42+
out,
43+
sbt.io.IO.readLines(in) .map{(line) => line match {
44+
case HeaderLine(title, level) => s"${"=" * level} $title ${"=" * level}"
45+
case other => other
46+
}}
47+
)
48+
} else {
49+
sbt.io.IO.delete(out)
50+
}
51+
out
52+
},
53+
)
54+
55+
override lazy val projectSettings = unscopedSettings ++ perScopeSettings(Compile) ++ perScopeSettings(Test)
56+
}

0 commit comments

Comments
 (0)