Fix plain text readme rendering

This commit is contained in:
Naoki Takezoe
2017-10-22 20:31:01 +09:00
parent 5a005cf5a6
commit 6bf71827f0
4 changed files with 13 additions and 13 deletions

View File

@@ -3,6 +3,7 @@ package gitbucket.core.plugin
import gitbucket.core.controller.Context
import gitbucket.core.service.RepositoryService
import gitbucket.core.view.Markdown
import gitbucket.core.view.helpers.urlLink
import play.twirl.api.Html
/**
@@ -33,12 +34,7 @@ object MarkdownRenderer extends Renderer {
object DefaultRenderer extends Renderer {
override def render(request: RenderRequest): Html = {
import request._
Html(
s"<tt>${
fileContent.split("(\\r\\n)|\\n").map(xml.Utility.escape(_)).mkString("<br/>")
}</tt>"
)
Html(s"""<tt><pre class="plain">${urlLink(request.fileContent)}</pre></tt>""")
}
}

View File

@@ -346,10 +346,10 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
}
// This pattern comes from: http://stackoverflow.com/a/4390768/1771641 (extract-url-from-string)
private[this] val detectAndRenderLinksRegex = """(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,13}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))""".r
private[this] val urlRegex = """(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,13}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))""".r
def detectAndRenderLinks(text: String, repository: RepositoryInfo)(implicit context: Context): String = {
val matches = detectAndRenderLinksRegex.findAllMatchIn(text).toSeq
def urlLink(text: String): String = {
val matches = urlRegex.findAllMatchIn(text).toSeq
val (x, pos) = matches.foldLeft((collection.immutable.Seq.empty[Html], 0)){ case ((x, pos), m) =>
val url = m.group(0)
@@ -361,8 +361,7 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
}
// append rest fragment
val out = if (pos < text.length) x :+ HtmlFormat.escape(text.substring(pos)) else x
decorateHtml(HtmlFormat.fill(out).toString, repository)
HtmlFormat.fill(out).toString
}
/**

View File

@@ -25,7 +25,7 @@
@if(pathList.isEmpty) {
@repository.repository.description.map { description =>
<p class="pc" style="margin-bottom: 10px;">
<span class="normal muted">@Html(helpers.detectAndRenderLinks(description, repository))</span>
<span class="normal muted">@Html(helpers.decorateHtml(helpers.urlLink(description), repository))</span>
</p>
}
}

View File

@@ -584,6 +584,11 @@ pre.blob {
font-size: 12px;
}
div.markdown-body pre.plain {
background: white;
font-size: 14px;
}
#readme {
margin-top: 20px;
}