Skip to content

Commit 25f5e08

Browse files
committed
Scala3doc: add documentation for API links
1 parent b0fd8c8 commit 25f5e08

File tree

3 files changed

+43
-30
lines changed

3 files changed

+43
-30
lines changed

docs/docs/usage/scala3doc/docComments.md

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,42 @@ title: API Documentation
44

55
# {{ page.title }}
66

7-
Scala3doc main feature is to create API documentation based on [doc comments](https://docs.scala-lang.org/style/scaladoc.html) known from scaladoc as well well as new syntax introduced in Scala 3.
7+
Scala3doc's main feature is creating API documentation from code comments.
88

9-
## New syntax
9+
By default, the code comments are understood as Markdown, though we also support
10+
Scaladoc's old [Wiki syntax](https://docs.scala-lang.org/style/scaladoc.html).
1011

11-
### Links
12+
## Syntax
1213

13-
The goal with the link syntax was to be as Scaladoc-compatible as possible,
14-
while also making the links a bit more pleasant to type and read.
15-
For the time being, Scala3doc mostly keeps Scaladoc's definition link syntax. We
16-
did, however, implement some improvements to it:
14+
### Definition links
15+
16+
Our definition link syntax is quite close to Scaladoc's syntax, though we have made some
17+
quality-of-life improvements.
18+
19+
#### Basic syntax
20+
21+
A definition link looks as follows: `[[scala.collection.immutable.List]]`.
22+
23+
Which is to say, a definition link is a sequence of identifiers separated by
24+
`.`. The identifiers can be separated with `#` as well for Scaladoc compatibility.
25+
26+
By default, an identifier `id` references the first (in source order) entity
27+
named `id`. An identifier can end with `$`, which forces it to refer to a value
28+
(an object, a value, a given); an identifier can also end with `!`, which forces
29+
it to refer to a type (a class, a type alias, a type member).
30+
31+
The links are resolved relative to the current location in source. That is, when
32+
documenting a class, the links are relative to the entity enclosing the class (a
33+
package, a class, an object); the same applies to documenting definitions.
34+
35+
Special characters in links can be backslash-escaped, which makes them part of
36+
identifiers instead. For example, `` [[scala.collection.immutable\.List]] ``
37+
references the class named `` `immutable.List` `` in package `scala.collection`.
38+
39+
#### New syntax
40+
41+
We have extended Scaladoc definition links to make them a bit more pleasant to
42+
write and read in source. The new syntax features are:
1743

1844
1. `package` can be used as a prefix to reference the enclosing package
1945
Example:
@@ -51,7 +77,7 @@ did, however, implement some improvements to it:
5177
Scaladoc required backslash-escaping to reference such identifiers. Instead,
5278
Scala3doc allows using the familiar Scala backtick quotation.
5379
54-
### Why keep the Wiki syntax?
80+
#### Why keep the Wiki syntax for links?
5581
5682
There are a few reasons why we've kept the Wiki syntax for documentation links
5783
instead of reusing the Markdown syntax. Those are:
@@ -67,4 +93,4 @@ instead of reusing the Markdown syntax. Those are:
6793
6894
None of these make it completely impossible to use the standard Markdown link
6995
syntax, but they make it much more awkward and ugly than it needs to be. On top
70-
of that, Markdown link syntax doesn't even save any characters.
96+
of that, Markdown link syntax doesn't even save any characters.
Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
11
---
2-
title: Dottydoc Specific Tags and Behavior
2+
title: Scala3doc-specific Tags and Features
33
---
44

55
# {{page.title}}
66

7-
Scala3doc extends markdown with some unique behaviors such as linking to API. This can be used from within static documentation and blog posts to provide blend-in content.
7+
Scala3doc extends Markdown with additional features, such as linking
8+
to API definitions. This can be used from within static documentation and blog
9+
posts to provide blend-in content.
810

911
## Linking to API
1012

11-
If you for instance, want to link to `scala.collection.immutable.Seq` in a
12-
markdown file, you can simply use the canonical path in your url:
13-
14-
```markdown
15-
[Seq](scala.collection.immutable.Seq)
16-
```
17-
18-
Linking to members is done in the same fashion:
19-
20-
```markdown
21-
[Seq](scala.collection.immutable.Seq.isEmpty)
22-
```
23-
24-
Scala3doc denotes objects by ending their names in "$". To select `List.range`
25-
you'd therefore write:
26-
27-
```markdown
28-
[List.range](scala.collection.immutable.List$.range)
29-
```
13+
Scala3doc allows linking to API documentation with Wiki-style links. Linking to
14+
`scala.collection.immutable.List` is as simple as
15+
`[[scala.collection.immutable.List]]`. For more information on the exact syntax, see [doc comment documentation](./docComments.html#definition-links).

scala3doc/src/dotty/dokka/site/common.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ val defaultMarkdownOptions: DataHolder =
2828
.set(AnchorLinkExtension.ANCHORLINKS_WRAP_TEXT, false)
2929
.set(AnchorLinkExtension.ANCHORLINKS_ANCHOR_CLASS, "anchor")
3030
.set(EmojiExtension.ROOT_IMAGE_PATH, "https://github.global.ssl.fastly.net/images/icons/emoji/")
31+
.set(WikiLinkExtension.LINK_ESCAPE_CHARS, "")
3132
.set(Parser.EXTENSIONS, java.util.Arrays.asList(
3233
TablesExtension.create(),
3334
TaskListExtension.create(),

0 commit comments

Comments
 (0)