Skip to content

WIP: Verify links in docs #17163

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
32 changes: 32 additions & 0 deletions scaladoc/src/dotty/tools/scaladoc/renderers/MemberRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import scala.jdk.CollectionConverters.*
import dotty.tools.scaladoc.translators.FilterAttributes
import org.jsoup.Jsoup
import translators.*
import java.net.URL
import scala.util.Try
import java.nio.file.{Files, Paths}

class MemberRenderer(signatureRenderer: SignatureRenderer)(using DocContext) extends DocRender(signatureRenderer):
import signatureRenderer._
Expand Down Expand Up @@ -100,6 +103,28 @@ class MemberRenderer(signatureRenderer: SignatureRenderer)(using DocContext) ext
def typeParams(m: Member): Seq[AppliedTag] = m.docs.fold(Nil)(d => flattenedDocPart(d.typeParams))
def valueParams(m: Member): Seq[AppliedTag] = m.docs.fold(Nil)(d => flattenedDocPart(d.valueParams))

def processLocalLinkWithGuard(str: String): String =
if str.startsWith("#") || str.isEmpty then
str
else
validationLink(str)

def validationLink(str: String): String =
def asValidURL = Try(URL(str)).toOption.map(_ => str)

def asAsset: Option[String] = Option.when(
Files.exists(Paths.get("docs/_assets").resolve(str))
)(
s"docs/_assets/$str"
)

asValidURL
.orElse(asAsset)
.getOrElse{
report.warning(s"Unable to resolve link '$str'")
str
}

def memberInfo(m: Member, withBrief: Boolean = false, full: Boolean = false): Seq[AppliedTag] =
val comment = m.docs
val bodyContents = m.docs.fold(Nil)(e => renderDocPart(e.body) :: Nil)
Expand All @@ -122,6 +147,13 @@ class MemberRenderer(signatureRenderer: SignatureRenderer)(using DocContext) ext
case _ => true
}

val document = Jsoup.parse(bodyContents.mkString)
val document2 = Jsoup.parse(attributes.mkString)

document.select("img").forEach(element =>
element.attr("src", validationLink(element.attr("src")))
)

Seq(
Option.when(withBrief && comment.flatMap(_.short).nonEmpty)(div(cls := "documentableBrief doc")(comment.flatMap(_.short).fold("")(renderDocPart))),
Option.when(bodyContents.nonEmpty || attributes.nonEmpty)(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ abstract class MarkupConversion[T](val repr: Repr)(using dctx: DocContext) {
case None => sym.dri
DocLink.ToDRI(dri, targetText)
case None =>
val txt = s"No DRI found for query"
val txt = s"No DRI found for query, the link seems to be wrong or the file may not exist."
val msg = s"$txt: $queryStr"

if (!summon[DocContext].args.noLinkWarnings) then
Expand Down