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.controller.Context
|
||||||
import gitbucket.core.service.RepositoryService
|
import gitbucket.core.service.RepositoryService
|
||||||
import gitbucket.core.view.Markdown
|
import gitbucket.core.view.Markdown
|
||||||
|
import gitbucket.core.view.helpers.urlLink
|
||||||
import play.twirl.api.Html
|
import play.twirl.api.Html
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,12 +34,7 @@ object MarkdownRenderer extends Renderer {
|
|||||||
|
|
||||||
object DefaultRenderer extends Renderer {
|
object DefaultRenderer extends Renderer {
|
||||||
override def render(request: RenderRequest): Html = {
|
override def render(request: RenderRequest): Html = {
|
||||||
import request._
|
Html(s"""<tt><pre class="plain">${urlLink(request.fileContent)}</pre></tt>""")
|
||||||
Html(
|
|
||||||
s"<tt>${
|
|
||||||
fileContent.split("(\\r\\n)|\\n").map(xml.Utility.escape(_)).mkString("<br/>")
|
|
||||||
}</tt>"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,4 +47,4 @@ case class RenderRequest(
|
|||||||
enableRefsLink: Boolean,
|
enableRefsLink: Boolean,
|
||||||
enableAnchor: Boolean,
|
enableAnchor: Boolean,
|
||||||
context: Context
|
context: Context
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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)
|
// 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 = {
|
def urlLink(text: String): String = {
|
||||||
val matches = detectAndRenderLinksRegex.findAllMatchIn(text).toSeq
|
val matches = urlRegex.findAllMatchIn(text).toSeq
|
||||||
|
|
||||||
val (x, pos) = matches.foldLeft((collection.immutable.Seq.empty[Html], 0)){ case ((x, pos), m) =>
|
val (x, pos) = matches.foldLeft((collection.immutable.Seq.empty[Html], 0)){ case ((x, pos), m) =>
|
||||||
val url = m.group(0)
|
val url = m.group(0)
|
||||||
@@ -361,8 +361,7 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
|
|||||||
}
|
}
|
||||||
// append rest fragment
|
// append rest fragment
|
||||||
val out = if (pos < text.length) x :+ HtmlFormat.escape(text.substring(pos)) else x
|
val out = if (pos < text.length) x :+ HtmlFormat.escape(text.substring(pos)) else x
|
||||||
|
HtmlFormat.fill(out).toString
|
||||||
decorateHtml(HtmlFormat.fill(out).toString, repository)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
@if(pathList.isEmpty) {
|
@if(pathList.isEmpty) {
|
||||||
@repository.repository.description.map { description =>
|
@repository.repository.description.map { description =>
|
||||||
<p class="pc" style="margin-bottom: 10px;">
|
<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>
|
</p>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -584,6 +584,11 @@ pre.blob {
|
|||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.markdown-body pre.plain {
|
||||||
|
background: white;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
#readme {
|
#readme {
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user