Skip to content

Commit

Permalink
SI-6580 Scaladoc: Should not close void elements
Browse files Browse the repository at this point in the history
Because it will generate a useless element like "</img>".

To made matters worse, Scaladoc used to generate the element with
attributes (like </img src="...">). That's why we had SI-6580.
  • Loading branch information
kzys committed Mar 25, 2013
1 parent fcc22e2 commit b4344e1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/compiler/scala/tools/nsc/doc/base/comment/Body.scala
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit b4344e1

Please sign in to comment.