Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SI-6580 Scaladoc: Should not close void elements #2278

Merged
merged 1 commit into from Mar 25, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/compiler/scala/tools/nsc/doc/base/comment/Body.scala
Expand Up @@ -75,16 +75,20 @@ object EntityLink {
def unapply(el: EntityLink): Option[(Inline, LinkTo)] = Some((el.title, el.link))
}
final case class HtmlTag(data: String) extends Inline {
def canClose(open: HtmlTag) = {
open.data.stripPrefix("<") == data.stripPrefix("</")
private val Pattern = """(?ms)\A<(/?)(.*?)[\s>].*\z""".r
private val (isEnd, tagName) = data match {
case Pattern(s1, s2) =>
(! s1.isEmpty, Some(s2.toLowerCase))
case _ =>
(false, None)
}

def close = {
if (data.indexOf("</") == -1)
Some(HtmlTag("</" + data.stripPrefix("<")))
else
None
def canClose(open: HtmlTag) = {
isEnd && tagName == open.tagName
}

private val TagsNotToClose = Set("br", "img")
def close = tagName collect { case name if !TagsNotToClose(name) => HtmlTag(s"</$name>") }
}

/** The summary of a comment, usually its first sentence. There must be exactly one summary per body. */
Expand Down
11 changes: 11 additions & 0 deletions test/scaladoc/run/SI-6580.check
@@ -0,0 +1,11 @@
Chain(List(Chain(List(Text(Here z(1) is defined as follows:), Text(
), HtmlTag(<br>), Text(
), Text( ), HtmlTag(<img src='http://example.com/fig1.png'>), Text(
), HtmlTag(<br>), Text(
), Text(plus z(1) times), Text(
), HtmlTag(<br>), Text(
), Text( ), HtmlTag(<img src='http://example.com/fig2.png'>), Text(
), HtmlTag(<br>), Text(
), Text(equals QL of something
)))))
Done.
32 changes: 32 additions & 0 deletions test/scaladoc/run/SI-6580.scala
@@ -0,0 +1,32 @@
import scala.tools.nsc.doc
import scala.tools.nsc.doc.model._
import scala.tools.nsc.doc.html.page.{Index, ReferenceIndex}
import scala.tools.partest.ScaladocModelTest

object Test extends ScaladocModelTest {
override def scaladocSettings = ""
override def code = """

object Test {
/** Here z(1) is defined as follows:
* <br>
* <img src='http://example.com/fig1.png'>
* <br>
* plus z(1) times
* <br>
* <img src='http://example.com/fig2.png'>
* <br>
* equals QL of something
*/
def f = 1
}

"""

def testModel(rootPackage: Package) {
import access._

val f = rootPackage._object("Test")._method("f")
println(f.comment.get.short)
}
}