mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-14 01:15:50 +01:00
Fix plain text readme rendering
This commit is contained in:
@@ -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>""")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -584,6 +584,11 @@ pre.blob {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
div.markdown-body pre.plain {
|
||||
background: white;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#readme {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user