mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-12 16:35:52 +01:00
Fix Markdown preview style
However styles in markdown-body affect tab. So there are invalid margin at the top of the tab.
This commit is contained in:
@@ -111,6 +111,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
enableRefsLink = params("enableRefsLink").toBoolean,
|
enableRefsLink = params("enableRefsLink").toBoolean,
|
||||||
enableLineBreaks = params("enableLineBreaks").toBoolean,
|
enableLineBreaks = params("enableLineBreaks").toBoolean,
|
||||||
enableTaskList = params("enableTaskList").toBoolean,
|
enableTaskList = params("enableTaskList").toBoolean,
|
||||||
|
enableAnchor = false,
|
||||||
hasWritePermission = hasWritePermission(repository.owner, repository.name, context.loginAccount)
|
hasWritePermission = hasWritePermission(repository.owner, repository.name, context.loginAccount)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -39,22 +39,28 @@ object Markdown {
|
|||||||
} else markdown
|
} else markdown
|
||||||
|
|
||||||
// escape task list
|
// escape task list
|
||||||
val source = if(enableTaskList){
|
val source = if(enableTaskList) escapeTaskList(s) else s
|
||||||
escapeTaskList(s)
|
|
||||||
} else s
|
|
||||||
|
|
||||||
val options = new Options()
|
val options = new Options()
|
||||||
options.setSanitize(true)
|
options.setSanitize(true)
|
||||||
options.setBreaks(enableLineBreaks)
|
options.setBreaks(enableLineBreaks)
|
||||||
val renderer = new GitBucketMarkedRenderer(options, repository, enableWikiLink, enableRefsLink, enableAnchor, enableTaskList, hasWritePermission, pages)
|
|
||||||
|
val renderer = new GitBucketMarkedRenderer(options, repository,
|
||||||
|
enableWikiLink, enableRefsLink, enableAnchor, enableTaskList, hasWritePermission, pages)
|
||||||
|
|
||||||
Marked.marked(source, options, renderer)
|
Marked.marked(source, options, renderer)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extends markedj Renderer for GitBucket
|
* Extends markedj Renderer for GitBucket
|
||||||
*/
|
*/
|
||||||
class GitBucketMarkedRenderer(options: Options, repository: RepositoryService.RepositoryInfo,
|
class GitBucketMarkedRenderer(options: Options,
|
||||||
enableWikiLink: Boolean, enableRefsLink: Boolean, enableAnchor: Boolean, enableTaskList: Boolean, hasWritePermission: Boolean,
|
repository: RepositoryService.RepositoryInfo,
|
||||||
|
enableWikiLink: Boolean,
|
||||||
|
enableRefsLink: Boolean,
|
||||||
|
enableAnchor: Boolean,
|
||||||
|
enableTaskList: Boolean,
|
||||||
|
hasWritePermission: Boolean,
|
||||||
pages: List[String])
|
pages: List[String])
|
||||||
(implicit val context: Context) extends Renderer(options) with LinkConverter with RequestCache {
|
(implicit val context: Context) extends Renderer(options) with LinkConverter with RequestCache {
|
||||||
|
|
||||||
@@ -62,11 +68,14 @@ object Markdown {
|
|||||||
val id = generateAnchorName(text)
|
val id = generateAnchorName(text)
|
||||||
val out = new StringBuilder()
|
val out = new StringBuilder()
|
||||||
|
|
||||||
out.append("<h" + level + " id=\"" + options.getHeaderPrefix + id + "\" class=\"markdown-head\">")
|
out.append("<h" + level + " id=\"" + options.getHeaderPrefix + id + "\"")
|
||||||
|
|
||||||
if(enableAnchor){
|
if(enableAnchor){
|
||||||
|
out.append(" class=\"markdown-head\">")
|
||||||
out.append("<a class=\"markdown-anchor-link\" href=\"#" + id + "\"></a>")
|
out.append("<a class=\"markdown-anchor-link\" href=\"#" + id + "\"></a>")
|
||||||
out.append("<a class=\"markdown-anchor\" name=\"" + id + "\"></a>")
|
out.append("<a class=\"markdown-anchor\" name=\"" + id + "\"></a>")
|
||||||
|
} else {
|
||||||
|
out.append(">")
|
||||||
}
|
}
|
||||||
|
|
||||||
out.append(text)
|
out.append(text)
|
||||||
@@ -83,22 +92,21 @@ object Markdown {
|
|||||||
var listType: String = null
|
var listType: String = null
|
||||||
if (ordered) {
|
if (ordered) {
|
||||||
listType = "ol"
|
listType = "ol"
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
listType = "ul"
|
listType = "ul"
|
||||||
}
|
}
|
||||||
if(body.contains("""class="task-list-item-checkbox"""")){
|
if(body.contains("""class="task-list-item-checkbox"""")){
|
||||||
return "<" + listType + " class=\"task-list\">\n" + body + "</" + listType + ">\n"
|
"<" + listType + " class=\"task-list\">\n" + body + "</" + listType + ">\n"
|
||||||
} else {
|
} else {
|
||||||
return "<" + listType + ">\n" + body + "</" + listType + ">\n"
|
"<" + listType + ">\n" + body + "</" + listType + ">\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override def listitem(text: String): String = {
|
override def listitem(text: String): String = {
|
||||||
if(text.contains("""class="task-list-item-checkbox" """)){
|
if(text.contains("""class="task-list-item-checkbox" """)){
|
||||||
return "<li class=\"task-list-item\">" + text + "</li>\n"
|
"<li class=\"task-list-item\">" + text + "</li>\n"
|
||||||
} else {
|
} else {
|
||||||
return "<li>" + text + "</li>\n"
|
"<li>" + text + "</li>\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
|
|||||||
enableWikiLink: Boolean,
|
enableWikiLink: Boolean,
|
||||||
enableRefsLink: Boolean,
|
enableRefsLink: Boolean,
|
||||||
enableLineBreaks: Boolean,
|
enableLineBreaks: Boolean,
|
||||||
|
enableAnchor: Boolean = true,
|
||||||
enableTaskList: Boolean = false,
|
enableTaskList: Boolean = false,
|
||||||
hasWritePermission: Boolean = false,
|
hasWritePermission: Boolean = false,
|
||||||
pages: List[String] = Nil)(implicit context: Context): Html =
|
pages: List[String] = Nil)(implicit context: Context): Html =
|
||||||
@@ -97,7 +98,7 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
|
|||||||
repository = repository,
|
repository = repository,
|
||||||
enableWikiLink = enableWikiLink,
|
enableWikiLink = enableWikiLink,
|
||||||
enableRefsLink = enableRefsLink,
|
enableRefsLink = enableRefsLink,
|
||||||
enableAnchor = true,
|
enableAnchor = enableAnchor,
|
||||||
enableLineBreaks = enableLineBreaks,
|
enableLineBreaks = enableLineBreaks,
|
||||||
enableTaskList = enableTaskList,
|
enableTaskList = enableTaskList,
|
||||||
hasWritePermission = hasWritePermission,
|
hasWritePermission = hasWritePermission,
|
||||||
|
|||||||
@@ -1718,28 +1718,34 @@ div.markdown-body h1 {
|
|||||||
border-bottom: 1px solid #ddd;
|
border-bottom: 1px solid #ddd;
|
||||||
font-size: 2.5em;
|
font-size: 2.5em;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
line-height: 1.7;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.markdown-body h2 {
|
div.markdown-body h2 {
|
||||||
border-bottom: 1px solid #eee;
|
border-bottom: 1px solid #eee;
|
||||||
font-size: 2em;
|
font-size: 2em;
|
||||||
|
line-height: 1.7;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.markdown-body h3 {
|
div.markdown-body h3 {
|
||||||
font-size: 1.5em;
|
font-size: 1.5em;
|
||||||
|
line-height: 1.7;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.markdown-body h4 {
|
div.markdown-body h4 {
|
||||||
font-size: 1.2em;
|
font-size: 1.2em;
|
||||||
|
line-height: 1.7;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.markdown-body h5 {
|
div.markdown-body h5 {
|
||||||
font-size: 1em;
|
font-size: 1em;
|
||||||
|
line-height: 1.7;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.markdown-body h6 {
|
div.markdown-body h6 {
|
||||||
color:#777;
|
color:#777;
|
||||||
font-size: 1em;
|
font-size: 1em;
|
||||||
|
line-height: 1.7;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.markdown-body li {
|
div.markdown-body li {
|
||||||
@@ -1905,7 +1911,6 @@ div.markdown-body table colgroup + tbody tr:first-child td:last-child {
|
|||||||
|
|
||||||
.markdown-head {
|
.markdown-head {
|
||||||
position: relative;
|
position: relative;
|
||||||
line-height: 1.7;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
a.markdown-anchor-link {
|
a.markdown-anchor-link {
|
||||||
|
|||||||
Reference in New Issue
Block a user