Skip to content

Commit e59c5ea

Browse files
Merge pull request #13202 from KacperFKorban/scaladoc/fix-13194
Ill formated codeblock
2 parents d140517 + 3397527 commit e59c5ea

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package tests.annotatedmarkdowncomment
2+
3+
/**
4+
*
5+
* This comment should be correctly rendered.
6+
*
7+
* ```scala
8+
* @experimental
9+
* class NotExperimental extends Any
10+
*
11+
* @deprecated
12+
* def commentInSwedish: String = "kommentar"
13+
* ```
14+
*
15+
* @syntax markdown
16+
*/
17+
class Luokassa

scaladoc/src/dotty/tools/scaladoc/snippets/FlexmarkSnippetProcessor.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ object FlexmarkSnippetProcessor:
4848
case result => result
4949
}
5050

51-
node.insertBefore(new ExtendedFencedCodeBlock(node, snippetCompilationResult))
51+
node.insertBefore(ExtendedFencedCodeBlock(node, snippetCompilationResult))
5252
node.unlink()
5353
}
5454
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ object Regexes {
7575

7676
/** The start of a Scaladoc code block */
7777
val CodeBlockStartRegex =
78-
new Regex("""(.*?)((?:\{\{\{)|(?:\u000E<pre(?: [^>]*)?>\u000E))(.*)""")
78+
new Regex("""(.*?)((?:\{\{\{)|(?:```)|(?:\u000E<pre(?: [^>]*)?>\u000E))(.*)""")
7979

8080
/** The end of a Scaladoc code block */
8181
val CodeBlockEndRegex =
82-
new Regex("""(.*?)((?:\}\}\})|(?:\u000E</pre>\u000E))(.*)""")
82+
new Regex("""(.*?)((?:\}\}\})|(?:```)|(?:\u000E</pre>\u000E))(.*)""")
8383
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ object Preparser {
3535
inCodeBlock: Boolean
3636
): PreparsedComment = remaining match {
3737
case CodeBlockStartRegex(before, marker, after) :: ls if !inCodeBlock =>
38-
if (!before.trim.isEmpty && !after.trim.isEmpty)
38+
if (!before.trim.isEmpty && !after.trim.isEmpty && marker == "```")
39+
go(docBody, tags, lastTagKey, before :: (marker + after) :: ls, inCodeBlock = false)
40+
else if (!before.trim.isEmpty && !after.trim.isEmpty)
3941
go(docBody, tags, lastTagKey, before :: marker :: after :: ls, inCodeBlock = false)
4042
else if (!before.trim.isEmpty)
4143
go(docBody, tags, lastTagKey, before :: marker :: ls, inCodeBlock = false)
42-
else if (!after.trim.isEmpty)
44+
else if (!after.trim.isEmpty && marker != "```")
4345
go(docBody, tags, lastTagKey, marker :: after :: ls, inCodeBlock = true)
4446
else lastTagKey match {
4547
case Some(key) =>
@@ -50,7 +52,7 @@ object Preparser {
5052
}
5153
go(docBody, tags + (key -> value), lastTagKey, ls, inCodeBlock = true)
5254
case None =>
53-
go(docBody append endOfLine append marker, tags, lastTagKey, ls, inCodeBlock = true)
55+
go(docBody append endOfLine append (marker + after), tags, lastTagKey, ls, inCodeBlock = true)
5456
}
5557

5658
case CodeBlockEndRegex(before, marker, after) :: ls =>

0 commit comments

Comments
 (0)