From fed7729dbb708ea2e1d138e79e20b9ec9bdbe3fd Mon Sep 17 00:00:00 2001 From: Kato Kazuyoshi Date: Tue, 22 Mar 2011 14:10:25 +0000 Subject: [scaladoc] Closes #4366. Review by pedrofurla. --- .../scala/tools/nsc/doc/model/comment/Body.scala | 13 +++++++- .../tools/nsc/doc/model/comment/Comment.scala | 35 +++++++++++++++++++++- .../nsc/doc/model/comment/CommentFactory.scala | 2 +- test/scaladoc/resources/Trac4366.scala | 8 +++++ test/scaladoc/scala/html/HtmlFactoryTest.scala | 26 ++++++++++++++++ test/scaladoc/scala/model/CommentFactoryTest.scala | 30 +++++++++++++++++++ 6 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 test/scaladoc/resources/Trac4366.scala diff --git a/src/compiler/scala/tools/nsc/doc/model/comment/Body.scala b/src/compiler/scala/tools/nsc/doc/model/comment/Body.scala index dd2093a88e..52ef154325 100644 --- a/src/compiler/scala/tools/nsc/doc/model/comment/Body.scala +++ b/src/compiler/scala/tools/nsc/doc/model/comment/Body.scala @@ -67,7 +67,18 @@ final case class Link(target: String, title: Inline) extends Inline final case class EntityLink(target: TemplateEntity) extends Inline final case class Monospace(text: String) extends Inline final case class Text(text: String) extends Inline -final case class HtmlTag(data: String) extends Inline +final case class HtmlTag(data: String) extends Inline { + def canClose(open: HtmlTag) = { + open.data.stripPrefix("<") == data.stripPrefix(" + list.foreach(scan) + case tag: HtmlTag => { + if (stack.length > 0 && tag.canClose(stack.last)) { + stack.remove(stack.length-1) + } else { + tag.close match { + case Some(t) => + stack += t + case None => + ; + } + } + } + case _ => + ; + } + } + scan(inline) + Chain(List(inline) ++ stack.reverse) + } + /** A shorter version of the body. Usually, this is the first sentence of the body. */ - def short: Inline = body.summary getOrElse Text("") + def short: Inline = { + body.summary match { + case Some(s) => + closeHtmlTags(s) + case _ => + Text("") + } + } /** A list of authors. The empty list is used when no author is defined. */ def authors: List[Body] diff --git a/src/compiler/scala/tools/nsc/doc/model/comment/CommentFactory.scala b/src/compiler/scala/tools/nsc/doc/model/comment/CommentFactory.scala index d82d5bfa5a..7485533641 100644 --- a/src/compiler/scala/tools/nsc/doc/model/comment/CommentFactory.scala +++ b/src/compiler/scala/tools/nsc/doc/model/comment/CommentFactory.scala @@ -172,7 +172,7 @@ trait CommentFactory { thisFactory: ModelFactory with CommentFactory => /** Safe HTML tags that can be kept. */ protected val SafeTags = - new Regex("""((&\w+;)|(&#\d+;)|(]*)?>.*)|(]*)?/?>))""") + new Regex("""((&\w+;)|(&#\d+;)|(]*)?>.*?)|(]*)?/?>))""") protected val safeTagMarker = '\u000E' diff --git a/test/scaladoc/resources/Trac4366.scala b/test/scaladoc/resources/Trac4366.scala new file mode 100644 index 0000000000..d117ffa903 --- /dev/null +++ b/test/scaladoc/resources/Trac4366.scala @@ -0,0 +1,8 @@ +class Trac4366 { + /** + * foo has been deprecated and will be removed in a future version of + * ScalaTest. Please call bar instead. + */ + @deprecated // deprecated in 1.0, remove in 1.4 + val foo: Option[String] = None +} diff --git a/test/scaladoc/scala/html/HtmlFactoryTest.scala b/test/scaladoc/scala/html/HtmlFactoryTest.scala index f0f1cd7e49..ecdbb3cf46 100644 --- a/test/scaladoc/scala/html/HtmlFactoryTest.scala +++ b/test/scaladoc/scala/html/HtmlFactoryTest.scala @@ -98,4 +98,30 @@ object Test extends Properties("HtmlFactory") { val files = createTemplates("Trac4306.scala") files("com/example/trac4306/foo/package$$Bar.html") != None } + + property("Trac #4366") = { + val files = createTemplates("Trac4366.scala") + files("Trac4366.html") match { + case node: scala.xml.Node => { + val comments = XMLUtil.stripGroup(node).descendant.flatMap { + case e: scala.xml.Elem => { + if (e.attribute("class").toString.contains("shortcomment")) { + Some(e) + } else { + None + } + } + case _ => None + } + + comments.exists { + (e) => { + val s = e.toString + s.contains("foo") && s.contains("") + } + } + } + case _ => false + } + } } diff --git a/test/scaladoc/scala/model/CommentFactoryTest.scala b/test/scaladoc/scala/model/CommentFactoryTest.scala index afe27dace0..25a91b1fa2 100644 --- a/test/scaladoc/scala/model/CommentFactoryTest.scala +++ b/test/scaladoc/scala/model/CommentFactoryTest.scala @@ -18,6 +18,9 @@ class Factory(val g: Global, val s: doc.Settings) def parseComment(s: String): Option[Inline] = strip(parse(s, "", scala.tools.nsc.util.NoPosition)) + + def createBody(s: String) = + parse(s, "", scala.tools.nsc.util.NoPosition).body } object Test extends Properties("CommentFactory") { @@ -95,4 +98,31 @@ object Test extends Properties("CommentFactory") { Text("\n"), HtmlTag(""))))))) ) + + property("Trac #4366 - body") = { + val body = factory.createBody( + """ + /** + * foo has been deprecated and will be removed in a future version. Please call bar instead. + */ + """ + ) + + body == Body(List(Paragraph(Chain(List( + Summary(Chain(List(Chain(List(HtmlTag(""), HtmlTag("foo"), Text(" has been deprecated and will be removed in a future version"))), Text(".")))), + Chain(List(Text(" Please call "), HtmlTag("bar"), Text(" instead."), HtmlTag(""), Text("\n"), Text(""))) + ))))) + } + + property("Trac #4366 - summary") = { + val body = factory.createBody( + """ + /** + * foo has been deprecated and will be removed in a future version. Please call bar instead. + */ + """ + ) + + body.summary == Some(Chain(List(Chain(List(HtmlTag(""), HtmlTag("foo"), Text(" has been deprecated and will be removed in a future version"))), Text(".")))) + } } -- cgit v1.2.3