Skip to content

Commit

Permalink
Merge pull request #13202 from KacperFKorban/scaladoc/fix-13194
Browse files Browse the repository at this point in the history
Ill formated codeblock
  • Loading branch information
KacperFKorban authored Jul 29, 2021
2 parents d140517 + 3397527 commit e59c5ea
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
17 changes: 17 additions & 0 deletions scaladoc-testcases/src/tests/annotatedmarkdowncomment.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package tests.annotatedmarkdowncomment

/**
*
* This comment should be correctly rendered.
*
* ```scala
* @experimental
* class NotExperimental extends Any
*
* @deprecated
* def commentInSwedish: String = "kommentar"
* ```
*
* @syntax markdown
*/
class Luokassa
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ object FlexmarkSnippetProcessor:
case result => result
}

node.insertBefore(new ExtendedFencedCodeBlock(node, snippetCompilationResult))
node.insertBefore(ExtendedFencedCodeBlock(node, snippetCompilationResult))
node.unlink()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ object Regexes {

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

/** The end of a Scaladoc code block */
val CodeBlockEndRegex =
new Regex("""(.*?)((?:\}\}\})|(?:\u000E</pre>\u000E))(.*)""")
new Regex("""(.*?)((?:\}\}\})|(?:```)|(?:\u000E</pre>\u000E))(.*)""")
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ object Preparser {
inCodeBlock: Boolean
): PreparsedComment = remaining match {
case CodeBlockStartRegex(before, marker, after) :: ls if !inCodeBlock =>
if (!before.trim.isEmpty && !after.trim.isEmpty)
if (!before.trim.isEmpty && !after.trim.isEmpty && marker == "```")
go(docBody, tags, lastTagKey, before :: (marker + after) :: ls, inCodeBlock = false)
else if (!before.trim.isEmpty && !after.trim.isEmpty)
go(docBody, tags, lastTagKey, before :: marker :: after :: ls, inCodeBlock = false)
else if (!before.trim.isEmpty)
go(docBody, tags, lastTagKey, before :: marker :: ls, inCodeBlock = false)
else if (!after.trim.isEmpty)
else if (!after.trim.isEmpty && marker != "```")
go(docBody, tags, lastTagKey, marker :: after :: ls, inCodeBlock = true)
else lastTagKey match {
case Some(key) =>
Expand All @@ -50,7 +52,7 @@ object Preparser {
}
go(docBody, tags + (key -> value), lastTagKey, ls, inCodeBlock = true)
case None =>
go(docBody append endOfLine append marker, tags, lastTagKey, ls, inCodeBlock = true)
go(docBody append endOfLine append (marker + after), tags, lastTagKey, ls, inCodeBlock = true)
}

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

0 comments on commit e59c5ea

Please sign in to comment.