Skip to content

Commit e6f95d5

Browse files
BarkingBadKacperFKorban
authored andcommitted
Start work on handling hide directives in code snippets
1 parent 86e9a42 commit e6f95d5

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

scaladoc-js/src/Main.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ package dotty.tools.scaladoc
33
object Main extends App {
44
Searchbar()
55
SocialLinks()
6+
CodeSnippets()
67
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package dotty.tools.scaladoc
2+
3+
import org.scalajs.dom._
4+
import org.scalajs.dom.ext._
5+
6+
class CodeSnippets:
7+
val replacePatternsAndResults = Seq(
8+
// ("", ""), // hide block directives
9+
("""(\/\/.*)(\n|\$)""", ""), // single line comment
10+
// ("", ""), // multi line comment
11+
)
12+
13+
document.querySelectorAll("code").foreach {
14+
case e: html.Element => e.innerHTML = replacePatternsAndResults.foldLeft(e.innerHTML) {
15+
case (acc, (pattern, result)) => acc.replaceAll(pattern, """<span class="hideable;">$1</span>""")
16+
}
17+
}

scaladoc-testcases/src/tests/methodsAndConstructors.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
package tests.methodsAndConstructors
22

3+
4+
/**
5+
* This is my codeblock
6+
*
7+
* ```
8+
* //{{
9+
* import xd
10+
* import xd2
11+
* //}}
12+
*
13+
*
14+
* val x = 1 // This is my valid comment
15+
*
16+
* /*
17+
* Is this my comment?
18+
* */
19+
*
20+
* val y = 2
21+
* ```
22+
*
23+
* The end of my codeblock
24+
*/
325
class A
426
class B extends A
527
class C

scaladoc/src/dotty/tools/scaladoc/tasty/comments/MemberLookup.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ trait MemberLookup {
148148
}
149149

150150
if owner.isPackageDef then
151-
findMatch(hackMembersOf(owner))
151+
findMatch(hackMembersOf(owner).flatMap {
152+
s =>
153+
(if s.name.endsWith("package$") then hackMembersOf(s) else Iterator.empty) ++ Iterator(s)
154+
})
152155
else
153156
owner.tree match {
154157
case tree: ClassDef =>

0 commit comments

Comments
 (0)