Skip to content

Commit bed92d3

Browse files
committed
wip
1 parent 084ab1a commit bed92d3

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

docs/_docs/reference/overview.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ In this reference, we discuss design decisions and present important differences
1010

1111
## Goals
1212

13-
The language redesign was guided by three main goals:
13+
The language [[foo.Bar.<]] redesign was guided by three main goals:
1414

1515
- Strengthen Scala's foundations.
1616
Make the full programming language compatible with the foundational work on the

scaladoc/src/dotty/tools/scaladoc/renderers/SiteRenderer.scala

+10-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import java.nio.file.Path
1313
import java.nio.file.Files
1414
import java.io.File
1515
import scala.util.chaining._
16+
import dotty.tools.scaladoc.util.Escape.escapeFilename
17+
import scala.util.control.NonFatal
1618

1719
case class ResolvedTemplate(template: LoadedTemplate, ctx: StaticSiteContext):
1820
val resolved = template.resolveToHtml(ctx)
@@ -55,11 +57,17 @@ trait SiteRenderer(using DocContext) extends Locations:
5557
val staticSiteRootPath = content.ctx.root.toPath.toAbsolutePath
5658
def asValidURL: Option[String] = Try(URI(str).toURL).toOption.map(_ => str)
5759
def asAsset: Option[String] = Option.when(
58-
Files.exists(staticSiteRootPath.resolve("_assets").resolve(str.stripPrefix("/")))
60+
try
61+
Files.exists(staticSiteRootPath.resolve("_assets").resolve(str.stripPrefix("/")))
62+
catch
63+
case NonFatal(_) => false
5964
)(
6065
resolveLink(pageDri, str.stripPrefix("/"))
6166
)
62-
def asStaticSite: Option[String] = tryAsDriPlain(str).orElse(tryAsDri(str))
67+
def asStaticSite: Option[String] =
68+
tryAsDriPlain(str)
69+
.orElse(tryAsDri(str))
70+
.orElse(tryAsDriPlain(escapeFilename(str)))
6371

6472
/* Link resolving checks performs multiple strategies with following priority:
6573
1. We check if the link is a valid URL e.g. http://dotty.epfl.ch

scaladoc/src/dotty/tools/scaladoc/site/StaticSiteContext.scala

+8-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import java.nio.file.FileVisitOption
77
import java.nio.file.Path
88
import java.nio.file.Paths
99

10-
import scala.util.Try
10+
import scala.util.control.NonFatal
1111
import scala.jdk.CollectionConverters._
1212
import scala.annotation.static
1313

@@ -75,10 +75,13 @@ class StaticSiteContext(
7575
val templateSourceLocation = staticSiteRoot.reverseSiteMappings.get(templateDestLocation)
7676

7777
// Check if link is relative or absolute
78-
if link.startsWith("/")
79-
then Seq(root.toPath.resolve(link.drop(1)))
80-
else Seq(templateDestLocation.getParent.resolve(link).normalize) ++
81-
templateSourceLocation.map(_.getParent.resolve(link).normalize)
78+
try
79+
if link.startsWith("/")
80+
then Seq(root.toPath.resolve(link.drop(1)))
81+
else Seq(templateDestLocation.getParent.resolve(link).normalize) ++
82+
templateSourceLocation.map(_.getParent.resolve(link).normalize)
83+
catch
84+
case NonFatal(_) => Seq.empty
8285

8386
// Try to strip site extension and create all possible file paths
8487
val fileNames = if siteExtensions.exists(link.endsWith(_))

scaladoc/src/dotty/tools/scaladoc/util/escape.scala

+17
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,24 @@ object Escape:
55
.replace("#","%23")
66

77
def escapeFilename(filename: String) =
8+
// from compiler/src/dotty/tools/dotc/util/NameTransformer.scala
89
val escaped = filename
10+
.replace("~", "$tilde")
11+
.replace("=", "$eq")
12+
.replace("<", "$less")
13+
.replace(">", "$greater")
14+
.replace("!", "$bang")
15+
.replace("#", "$hash")
16+
.replace("%", "$percent")
17+
.replace("^", "$up")
18+
.replace("&", "$amp")
19+
.replace("|", "$bar")
20+
.replace("*", "$times")
921
.replace("/", "$div")
22+
.replace("+", "$plus")
23+
.replace("-", "$minus")
24+
.replace(":", "$colon")
1025
.replace("\\", "$bslash")
26+
.replace("?", "$qmark")
27+
.replace("@", "$at")
1128
if escaped != filename then escaped + "$" else escaped

0 commit comments

Comments
 (0)