diff --git a/mdoc-docs/src/main/scala/mdoc/docs/SbtModifier.scala b/mdoc-docs/src/main/scala/mdoc/docs/SbtModifier.scala
index 8c5dbfb0a..152ddc4c4 100644
--- a/mdoc-docs/src/main/scala/mdoc/docs/SbtModifier.scala
+++ b/mdoc-docs/src/main/scala/mdoc/docs/SbtModifier.scala
@@ -14,6 +14,7 @@ class SbtModifier extends StringModifier {
mdocIn,
mdocOut,
mdocVariables,
+ mdocExtraArguments,
mdocAutoDependency
)
val rows = keys.map { s =>
@@ -21,6 +22,7 @@ class SbtModifier extends StringModifier {
.toString()
.replaceAllLiterally("java.lang.String", "String")
.replaceAllLiterally("scala.collection.immutable.", "")
+ .replaceAllLiterally("scala.collection.", "")
{s.key.toString} |
{tpe} |
diff --git a/mdoc-sbt/src/main/scala/mdoc/MdocPlugin.scala b/mdoc-sbt/src/main/scala/mdoc/MdocPlugin.scala
index c08169b26..84649964a 100644
--- a/mdoc-sbt/src/main/scala/mdoc/MdocPlugin.scala
+++ b/mdoc-sbt/src/main/scala/mdoc/MdocPlugin.scala
@@ -36,6 +36,11 @@ object MdocPlugin extends AutoPlugin {
"Output directory for mdoc generated markdown. " +
"Defaults to the target/mdoc directory of this project."
)
+ val mdocExtraArguments =
+ settingKey[Seq[String]](
+ "Additional command-line arguments to pass on every mdoc invocation. " +
+ "For example, add --no-link-hygiene to disable link hygiene."
+ )
val mdocAutoDependency =
settingKey[Boolean](
"If false, do not add mdoc as a library dependency this project. " +
@@ -49,10 +54,12 @@ object MdocPlugin extends AutoPlugin {
mdocOut := target.in(Compile).value / "mdoc",
mdocVariables := Map.empty,
mdocAutoDependency := true,
+ mdocExtraArguments := Nil,
mdoc := Def.inputTaskDyn {
val parsed = sbt.complete.DefaultParsers.spaceDelimited("").parsed
+ val args = mdocExtraArguments.value ++ parsed
Def.taskDyn {
- runMain.in(Compile).toTask(s" mdoc.Main ${parsed.mkString(" ")}")
+ runMain.in(Compile).toTask(s" mdoc.Main ${args.mkString(" ")}")
}
}.evaluated,
libraryDependencies ++= {
diff --git a/mdoc/src/main/scala/mdoc/MainSettings.scala b/mdoc/src/main/scala/mdoc/MainSettings.scala
index 14a6ebdae..2088e3e9e 100644
--- a/mdoc/src/main/scala/mdoc/MainSettings.scala
+++ b/mdoc/src/main/scala/mdoc/MainSettings.scala
@@ -71,6 +71,9 @@ final class MainSettings private (
def withCheck(check: Boolean): MainSettings = {
copy(settings.copy(check = check))
}
+ def withNoLinkHygiene(noLinkHygiene: Boolean): MainSettings = {
+ copy(settings.copy(noLinkHygiene = noLinkHygiene))
+ }
def withReportRelativePaths(reportRelativePaths: Boolean): MainSettings = {
copy(settings.copy(reportRelativePaths = reportRelativePaths))
}
diff --git a/mdoc/src/main/scala/mdoc/internal/cli/MainOps.scala b/mdoc/src/main/scala/mdoc/internal/cli/MainOps.scala
index 258c0f73f..ddc663289 100644
--- a/mdoc/src/main/scala/mdoc/internal/cli/MainOps.scala
+++ b/mdoc/src/main/scala/mdoc/internal/cli/MainOps.scala
@@ -44,7 +44,7 @@ final class MainOps(
}
def lint(): Unit = {
- if (settings.out.isDirectory) {
+ if (settings.out.isDirectory && !settings.noLinkHygiene) {
val docs = DocumentLinks.fromGeneratedSite(settings, reporter)
LinkHygiene.lint(docs, reporter, settings.verbose)
}
diff --git a/mdoc/src/main/scala/mdoc/internal/cli/Settings.scala b/mdoc/src/main/scala/mdoc/internal/cli/Settings.scala
index 7efe1ee9d..25e7d32b7 100644
--- a/mdoc/src/main/scala/mdoc/internal/cli/Settings.scala
+++ b/mdoc/src/main/scala/mdoc/internal/cli/Settings.scala
@@ -51,6 +51,8 @@ case class Settings(
)
@ExtraName("test")
check: Boolean = false,
+ @Description("Disable link hygiene analysis so that no warnings are reported for dead links.")
+ noLinkHygiene: Boolean = false,
@Description("Include additional diagnostics for debugging potential problems.")
verbose: Boolean = false,
@Description(
diff --git a/tests/unit/src/test/scala/tests/markdown/BaseMarkdownSuite.scala b/tests/unit/src/test/scala/tests/markdown/BaseMarkdownSuite.scala
index f48d0d860..16af96d4b 100644
--- a/tests/unit/src/test/scala/tests/markdown/BaseMarkdownSuite.scala
+++ b/tests/unit/src/test/scala/tests/markdown/BaseMarkdownSuite.scala
@@ -70,6 +70,7 @@ abstract class BaseMarkdownSuite extends org.scalatest.FunSuite with DiffAsserti
print(colorOut)
val stdout = fansi.Str(colorOut).plainText
assert(!reporter.hasErrors, stdout)
+ assert(!reporter.hasWarnings, stdout)
assertNoDiffOrPrintExpected(obtained, expected)
}
}
diff --git a/tests/unit/src/test/scala/tests/markdown/NoLinkWarningSuite.scala b/tests/unit/src/test/scala/tests/markdown/NoLinkWarningSuite.scala
new file mode 100644
index 000000000..b5ea420e4
--- /dev/null
+++ b/tests/unit/src/test/scala/tests/markdown/NoLinkWarningSuite.scala
@@ -0,0 +1,25 @@
+package tests.markdown
+
+import tests.cli.BaseCliSuite
+
+class NoLinkWarningSuite extends BaseCliSuite {
+ val original =
+ """/readme.md
+ |# Header
+ |
+ |[Head](#head)
+ """.stripMargin
+
+ checkCli(
+ "nowarn",
+ original,
+ original,
+ extraArgs = Array(
+ "--no-link-hygiene"
+ ),
+ onStdout = { out =>
+ assert(!out.contains("warning"))
+ }
+ )
+
+}