diff options
author | Philippus Baalman <philippus@gmail.com> | 2017-02-22 21:34:35 +0100 |
---|---|---|
committer | Philippus Baalman <philippus@gmail.com> | 2017-02-25 14:44:32 +0100 |
commit | e3c5df8ec369047d73a54ed94caebe0a4f26627c (patch) | |
tree | 991d33ded453604cf7df71f1794e4dc0f4ad5f77 /src/scaladoc | |
parent | cbf7daa57d70ccacf8cfc7c2f4a7c0e81e1c773a (diff) | |
download | scala-e3c5df8ec369047d73a54ed94caebe0a4f26627c.tar.gz scala-e3c5df8ec369047d73a54ed94caebe0a4f26627c.tar.bz2 scala-e3c5df8ec369047d73a54ed94caebe0a4f26627c.zip |
added missing Inline matches to inlineToStr so it is now exhaustive
scala.xml.XML.loadString(tag).text will remove all html tags inside the HtmlTag
use a regex to remove html tags inside the tag
added some tests for the inlineToStr-method
moved inlineToStr to companion object of Page
added test for nested html tags
Diffstat (limited to 'src/scaladoc')
3 files changed, 22 insertions, 17 deletions
diff --git a/src/scaladoc/scala/tools/nsc/doc/html/Page.scala b/src/scaladoc/scala/tools/nsc/doc/html/Page.scala index c720c4939f..fb4b3c0273 100644 --- a/src/scaladoc/scala/tools/nsc/doc/html/Page.scala +++ b/src/scaladoc/scala/tools/nsc/doc/html/Page.scala @@ -7,7 +7,7 @@ package scala package tools.nsc.doc.html import scala.tools.nsc.doc.model._ -import scala.tools.nsc.doc.base.comment +import scala.tools.nsc.doc.base.comment._ import java.io.{FileOutputStream, File} import scala.reflect.NameTransformer import java.nio.channels.Channels @@ -106,16 +106,21 @@ abstract class Page { case dtpl: DocTemplateEntity => dtpl.companion.isDefined case _ => false } +} - protected def inlineToStr(inl: comment.Inline): String = inl match { - case comment.Chain(items) => items flatMap (inlineToStr(_)) mkString "" - case comment.Italic(in) => inlineToStr(in) - case comment.Bold(in) => inlineToStr(in) - case comment.Underline(in) => inlineToStr(in) - case comment.Monospace(in) => inlineToStr(in) - case comment.Text(text) => text - case comment.Summary(in) => inlineToStr(in) - case comment.EntityLink(comment.Text(text), _) => text - case _ => inl.toString +object Page { + def inlineToStr(inl: Inline): String = inl match { + case Chain(items) => items flatMap (inlineToStr(_)) mkString "" + case Italic(in) => inlineToStr(in) + case Bold(in) => inlineToStr(in) + case Underline(in) => inlineToStr(in) + case Superscript(in) => inlineToStr(in) + case Subscript(in) => inlineToStr(in) + case Link(raw, title) => inlineToStr(title) + case Monospace(in) => inlineToStr(in) + case Text(text) => text + case Summary(in) => inlineToStr(in) + case HtmlTag(tag) => "<[^>]*>".r.replaceAllIn(tag, "") + case EntityLink(Text(text), _) => text } } diff --git a/src/scaladoc/scala/tools/nsc/doc/html/page/Entity.scala b/src/scaladoc/scala/tools/nsc/doc/html/page/Entity.scala index 54bf42bbd5..fb2bf5049f 100644 --- a/src/scaladoc/scala/tools/nsc/doc/html/page/Entity.scala +++ b/src/scaladoc/scala/tools/nsc/doc/html/page/Entity.scala @@ -90,13 +90,13 @@ trait EntityPage extends HtmlPage { mbr match { case dtpl: DocTemplateEntity => dtpl.companion.fold(<span class="separator"></span>) { c: DocTemplateEntity => - <a class="object" href={relativeLinkTo(c)} title={c.comment.fold("")(com => inlineToStr(com.short))}></a> + <a class="object" href={relativeLinkTo(c)} title={c.comment.fold("")(com => Page.inlineToStr(com.short))}></a> } case _ => <span class="separator"></span> } } - <a class={mbr.kind} href={relativeLinkTo(mbr)} title={mbr.comment.fold("")(com => inlineToStr(com.short))}></a> - <a href={relativeLinkTo(mbr)} title={mbr.comment.fold("")(com => inlineToStr(com.short))}> + <a class={mbr.kind} href={relativeLinkTo(mbr)} title={mbr.comment.fold("")(com => Page.inlineToStr(com.short))}></a> + <a href={relativeLinkTo(mbr)} title={mbr.comment.fold("")(com => Page.inlineToStr(com.short))}> {mbr.name} </a> </li> @@ -897,7 +897,7 @@ trait EntityPage extends HtmlPage { } } if (!nameLink.isEmpty) - <a title={mbr.comment.fold("")(c => inlineToStr(c.short))} href={nameLink}> + <a title={mbr.comment.fold("")(c => Page.inlineToStr(c.short))} href={nameLink}> {nameHtml} </a> else nameHtml @@ -1065,7 +1065,7 @@ trait EntityPage extends HtmlPage { body.blocks flatMap (blockToStr(_)) mkString "" private def blockToStr(block: comment.Block): String = block match { - case comment.Paragraph(in) => inlineToStr(in) + case comment.Paragraph(in) => Page.inlineToStr(in) case _ => block.toString } diff --git a/src/scaladoc/scala/tools/nsc/doc/html/page/IndexScript.scala b/src/scaladoc/scala/tools/nsc/doc/html/page/IndexScript.scala index 8f58a7b845..28304e76c7 100644 --- a/src/scaladoc/scala/tools/nsc/doc/html/page/IndexScript.scala +++ b/src/scaladoc/scala/tools/nsc/doc/html/page/IndexScript.scala @@ -87,7 +87,7 @@ class IndexScript(universe: doc.Universe) extends Page { /** Gets the short description i.e. the first sentence of the docstring */ def shortDesc(mbr: MemberEntity): String = mbr.comment.fold("") { c => - inlineToStr(c.short).replaceAll("\n", "") + Page.inlineToStr(c.short).replaceAll("\n", "") } /** Returns the json representation of the supplied members */ |