@@ -4,14 +4,17 @@ package tasty.comments
4
4
import scala .collection .mutable
5
5
import scala .collection .immutable .SortedMap
6
6
import scala .util .matching .Regex
7
+ import java .net .URL
8
+ import java .nio .file .{Paths , Files }
9
+ import scala .util .Try
7
10
8
11
object Preparser {
9
12
import Regexes ._
10
13
11
14
/** Parses a raw comment string into a `Comment` object. */
12
15
def preparse (
13
16
comment : List [String ],
14
- ): PreparsedComment = {
17
+ )( using DocContext ) : PreparsedComment = {
15
18
16
19
/** Parses a comment (in the form of a list of lines) to a `Comment`
17
20
* instance, recursively on lines. To do so, it splits the whole comment
@@ -129,7 +132,38 @@ object Preparser {
129
132
val stripTags = List (inheritDiagramTag, contentDiagramTag, SimpleTagKey (" template" ), SimpleTagKey (" documentable" ))
130
133
val tagsWithoutDiagram = tags.filterNot(pair => stripTags.contains(pair._1))
131
134
135
+ def processLink : Unit =
136
+ if (! summon[DocContext ].args.noLinkWarnings) then tags.get(SimpleTagKey (" see" )).get.foreach(link => {
137
+ val newLink : String = link.replaceAll(" \\ [\\ [|\\ ]\\ ]" , " " )
138
+ val isValid = Try (new URL (newLink)).isSuccess
139
+ isValid match {
140
+ case true =>
141
+ val url = new URL (newLink)
142
+ url match {
143
+ // We check if it's an internal link
144
+ case s if s.getPath.contains(" /docs/" ) =>
145
+ if (newLink.contains(" oracle" )) then // exclude links containing "oracle"
146
+ None
147
+ else
148
+ // We check if the internal link to the static documentation is valid
149
+ val docPath = url.getPath.substring(url.getPath.indexOf(" /docs/" )).replaceFirst(" /docs/" , " docs/_docs/" ).replace(" .html" , " .md" )
150
+ println(docPath)
151
+ val fileExists = Files .exists(Paths .get(docPath))
152
+ if ! fileExists then
153
+ // Si le fichier n'existe pas, on vérifie si le fichier existe avec l'extension .md
154
+ val newDocPath = docPath + " .md"
155
+ if ! Files .exists(Paths .get(newDocPath)) then
156
+ report.warning(s " Link to $newLink will return a 404 not found " )
157
+ case _ => None
158
+ }
159
+ case false =>
160
+ None
161
+ }
162
+ })
163
+
132
164
val bodyTags : mutable.Map [TagKey , List [String ]] =
165
+ if tags.get(SimpleTagKey (" see" )).isDefined then
166
+ processLink
133
167
mutable.Map ((tagsWithoutDiagram).toSeq: _* )
134
168
135
169
def allTags (key : SimpleTagKey ): List [String ] =
0 commit comments