Skip to content

Commit cbf7daa

Browse files
authored
Merge pull request scala#5681 from Philippus/issue/9704
SI-9704 don't add a closing HtmlTag if it is already closed
2 parents effde0c + b8a8ac1 commit cbf7daa

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/scaladoc/scala/tools/nsc/doc/base/comment/Body.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ object EntityLink {
7474
def unapply(el: EntityLink): Option[(Inline, LinkTo)] = Some((el.title, el.link))
7575
}
7676
final case class HtmlTag(data: String) extends Inline {
77-
private val Pattern = """(?ms)\A<(/?)(.*?)[\s>].*\z""".r
7877
private val (isEnd, tagName) = data match {
79-
case Pattern(s1, s2) =>
78+
case HtmlTag.Pattern(s1, s2) =>
8079
(! s1.isEmpty, Some(s2.toLowerCase))
8180
case _ =>
8281
(false, None)
@@ -86,8 +85,13 @@ final case class HtmlTag(data: String) extends Inline {
8685
isEnd && tagName == open.tagName
8786
}
8887

88+
def close = tagName collect {
89+
case name if !HtmlTag.TagsNotToClose(name) && !data.endsWith(s"</$name>") => HtmlTag(s"</$name>")
90+
}
91+
}
92+
object HtmlTag {
93+
private val Pattern = """(?ms)\A<(/?)(.*?)[\s>].*\z""".r
8994
private val TagsNotToClose = Set("br", "img")
90-
def close = tagName collect { case name if !TagsNotToClose(name) => HtmlTag(s"</$name>") }
9195
}
9296

9397
/** The summary of a comment, usually its first sentence. There must be exactly one summary per body. */

test/scaladoc/run/SI-9704.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Chain(List(Chain(List(Text(Demonstrates a scala issue in which the closing link tag is duplicated), Text(
2+
), HtmlTag(<a href="https://link">title</a>), Text(
3+
), Text()))))
4+
Done.

test/scaladoc/run/SI-9704.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import scala.tools.nsc.doc.model._
2+
import scala.tools.partest.ScaladocModelTest
3+
4+
object Test extends ScaladocModelTest {
5+
override def code = """
6+
object Foo {
7+
/**
8+
* Demonstrates a scala issue in which the closing link tag is duplicated
9+
* <a href="https://link">title</a>
10+
*/
11+
def bar = ???
12+
}
13+
"""
14+
15+
def scaladocSettings = ""
16+
17+
def testModel(root: Package) = {
18+
import access._
19+
val thing = root._object("Foo")._method("bar")
20+
println(thing.comment.get.short)
21+
}
22+
}

0 commit comments

Comments
 (0)