@@ -9,6 +9,9 @@ import scala.jdk.CollectionConverters.*
9
9
import dotty .tools .scaladoc .translators .FilterAttributes
10
10
import org .jsoup .Jsoup
11
11
import translators .*
12
+ import java .net .URL
13
+ import scala .util .Try
14
+ import java .nio .file .{Files , Paths }
12
15
13
16
class MemberRenderer (signatureRenderer : SignatureRenderer )(using DocContext ) extends DocRender (signatureRenderer):
14
17
import signatureRenderer ._
@@ -99,10 +102,73 @@ class MemberRenderer(signatureRenderer: SignatureRenderer)(using DocContext) ext
99
102
100
103
def typeParams (m : Member ): Seq [AppliedTag ] = m.docs.fold(Nil )(d => flattenedDocPart(d.typeParams))
101
104
def valueParams (m : Member ): Seq [AppliedTag ] = m.docs.fold(Nil )(d => flattenedDocPart(d.valueParams))
105
+
106
+ def processLocalLinkWithGuard (str : String ): String =
107
+ if str.startsWith(" #" ) || str.isEmpty then
108
+ str
109
+ else
110
+ validationLink(str)
111
+
112
+ def validationLink (str : String ): String =
113
+ def asValidURL = Try (URL (str)).toOption.map(_ => str)
114
+
115
+ def asAsset =
116
+ println(Paths .get(" src/main/ressources" ).resolve(str.stripPrefix(" /" )).toAbsolutePath)
117
+ println(Files .exists(Paths .get(" src/main/ressources" ).resolve(str.stripPrefix(" /" ))))
118
+ Option .when(
119
+ Files .exists(Paths .get(" src/main/ressources" ).resolve(str.stripPrefix(" /" )))
120
+ )(
121
+ s " src/main/ressources/ $str"
122
+ )
123
+
124
+ def asStaticSite = Option .when(
125
+ Files .exists(Paths .get(" docs/_docs" ).resolve(str.stripPrefix(" /" )))
126
+ )(
127
+ s " docs/_docs/ $str"
128
+ )
129
+
130
+ def asApiLink =
131
+ println(str)
132
+ println(Paths .get(" target/scala-3.3.1-RC1-bin-SNAPSHOT/api" ).resolve(str.stripPrefix(" ./" )).toAbsolutePath)
133
+ println(Files .exists(Paths .get(" target/scala-3.3.1-RC1-bin-SNAPSHOT/api" ).resolve(str.stripPrefix(" ./" ))))
134
+ Option .when(
135
+ Files .exists(Paths .get(" target/scala-3.3.1-RC1-bin-SNAPSHOT/api" ).resolve(str.stripPrefix(" ./" )))
136
+ )(
137
+ s " target/scala-3.3.1-RC1-bin-SNAPSHOT/api/ $str"
138
+ )
139
+
140
+
141
+ asValidURL
142
+ .orElse(asStaticSite)
143
+ .orElse(asAsset)
144
+ .orElse(asApiLink)
145
+ .getOrElse{
146
+ report.warning(s " Unable to resolve link ' $str' " )
147
+ str
148
+ }
149
+
150
+ // println(asValidURL)
151
+
152
+ // println(Paths.get("src/main/ressources").resolve(str.stripPrefix("/")).toAbsolutePath)
153
+ // println(Files.exists(Paths.get("src/main/ressources").resolve(str.stripPrefix("/"))))
154
+ // def asAsset = Option.when(
155
+ // Files.exists(Paths.get("docs/_assets").resolve(str.stripPrefix("/")))
156
+ // )(
157
+ // s"docs/_assets/$str"
158
+ // )
102
159
103
160
def memberInfo (m : Member , withBrief : Boolean = false , full : Boolean = false ): Seq [AppliedTag ] =
104
161
val comment = m.docs
105
162
val bodyContents = m.docs.fold(Nil )(e => renderDocPart(e.body) :: Nil )
163
+
164
+ val document = Jsoup .parse(bodyContents.mkString)
165
+ document.select(" a" ).forEach(element =>
166
+ element.attr(" href" , processLocalLinkWithGuard(element.attr(" href" )))
167
+ )
168
+
169
+ document.select(" img" ).forEach { element =>
170
+ element.attr(" src" , validationLink(element.attr(" src" )))
171
+ }
106
172
107
173
val classLikeInfo : TagArg = classLikeParts(m, full)
108
174
0 commit comments