diff options
author | Kato Kazuyoshi <kato.kazuyoshi@gmail.com> | 2011-03-22 14:10:25 +0000 |
---|---|---|
committer | Kato Kazuyoshi <kato.kazuyoshi@gmail.com> | 2011-03-22 14:10:25 +0000 |
commit | fed7729dbb708ea2e1d138e79e20b9ec9bdbe3fd (patch) | |
tree | 12f3750d096bd48a3cb6c2c3f97befd659731edb /src | |
parent | 063e8a9dfee3d2c889f9e2e28cda2e8a28aa61cc (diff) | |
download | scala-fed7729dbb708ea2e1d138e79e20b9ec9bdbe3fd.tar.gz scala-fed7729dbb708ea2e1d138e79e20b9ec9bdbe3fd.tar.bz2 scala-fed7729dbb708ea2e1d138e79e20b9ec9bdbe3fd.zip |
[scaladoc] Closes #4366. Review by pedrofurla.
Diffstat (limited to 'src')
3 files changed, 47 insertions, 3 deletions
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("</") + } + + def close = { + if (data.indexOf("</") == -1) + Some(HtmlTag("</" + data.stripPrefix("<"))) + else + None + } +} /** The summary of a comment, usually its first sentence. There must be exactly one summary per body. */ final case class Summary(text: Inline) extends Inline diff --git a/src/compiler/scala/tools/nsc/doc/model/comment/Comment.scala b/src/compiler/scala/tools/nsc/doc/model/comment/Comment.scala index e39907ac55..b3033188e9 100644 --- a/src/compiler/scala/tools/nsc/doc/model/comment/Comment.scala +++ b/src/compiler/scala/tools/nsc/doc/model/comment/Comment.scala @@ -18,8 +18,41 @@ abstract class Comment { /** The main body of the comment that describes what the entity does and is. */ def body: Body + private def closeHtmlTags(inline: Inline) = { + val stack = mutable.ListBuffer.empty[HtmlTag] + def scan(i: Inline): Unit = { + i match { + case Chain(list) => + 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+;)|(<code( [^>]*)?>.*</code>)|(</?(abbr|acronym|address|area|a|bdo|big|blockquote|br|button|b|caption|cite|col|colgroup|dd|del|dfn|em|fieldset|form|hr|img|input|ins|i|kbd|label|legend|link|map|object|optgroup|option|param|pre|q|samp|select|small|span|strong|sub|sup|table|tbody|td|textarea|tfoot|th|thead|tr|tt|var)( [^>]*)?/?>))""") + new Regex("""((&\w+;)|(&#\d+;)|(<code( [^>]*)?>.*?</code>)|(</?(abbr|acronym|address|area|a|bdo|big|blockquote|br|button|b|caption|cite|col|colgroup|dd|del|dfn|em|fieldset|form|hr|img|input|ins|i|kbd|label|legend|link|map|object|optgroup|option|param|pre|q|samp|select|small|span|strong|sub|sup|table|tbody|td|textarea|tfoot|th|thead|tr|tt|var)( [^>]*)?/?>))""") protected val safeTagMarker = '\u000E' |