@@ -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,30 @@ 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 (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
+ // We check if the internal link to the static documentation is valid
146
+ val fileExists = Files .exists(Paths .get(url.getPath().replaceFirst(" /docs/" , " docs/_docs/" ).replace(" .html" , " .md" )))
147
+ if ! fileExists then
148
+ report.warning(s " Link to $url will return a 404 not found " )
149
+ case _ => None
150
+ }
151
+ case false =>
152
+ report.warning(s " Link to $newLink is not valid " )
153
+ }
154
+ })
155
+
132
156
val bodyTags : mutable.Map [TagKey , List [String ]] =
157
+ if tags.get(SimpleTagKey (" see" )).isDefined then
158
+ processLink
133
159
mutable.Map ((tagsWithoutDiagram).toSeq: _* )
134
160
135
161
def allTags (key : SimpleTagKey ): List [String ] =
0 commit comments