Skip to content

Commit

Permalink
Ill formated codeblock
Browse files Browse the repository at this point in the history
  • Loading branch information
KacperFKorban committed Jul 29, 2021
1 parent c53cc91 commit b229147
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 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))(.*)""")
}
16 changes: 9 additions & 7 deletions scaladoc/src/dotty/tools/scaladoc/tasty/comments/Preparser.scala
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.nonEmpty && after.trim.nonEmpty && marker == "```")
go(docBody, tags, lastTagKey, before :: (marker + after) :: ls, inCodeBlock = false)
else if (before.trim.nonEmpty && after.trim.nonEmpty)
go(docBody, tags, lastTagKey, before :: marker :: after :: ls, inCodeBlock = false)
else if (!before.trim.isEmpty)
else if (before.trim.nonEmpty)
go(docBody, tags, lastTagKey, before :: marker :: ls, inCodeBlock = false)
else if (!after.trim.isEmpty)
else if (after.trim.nonEmpty && marker != "```")
go(docBody, tags, lastTagKey, marker :: after :: ls, inCodeBlock = true)
else lastTagKey match {
case Some(key) =>
Expand All @@ -50,15 +52,15 @@ 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 =>
if (!before.trim.isEmpty && !after.trim.isEmpty)
if (before.trim.nonEmpty && after.trim.nonEmpty)
go(docBody, tags, lastTagKey, before :: marker :: after :: ls, inCodeBlock = true)
if (!before.trim.isEmpty)
if (before.trim.nonEmpty)
go(docBody, tags, lastTagKey, before :: marker :: ls, inCodeBlock = true)
else if (!after.trim.isEmpty)
else if (after.trim.nonEmpty)
go(docBody, tags, lastTagKey, marker :: after :: ls, inCodeBlock = false)
else lastTagKey match {
case Some(key) =>
Expand Down

0 comments on commit b229147

Please sign in to comment.