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:
Naoki Takezoe
2016-01-16 22:00:29 +09:00
parent 15e8527e01
commit 9b3e8bd22b
4 changed files with 30 additions and 15 deletions

View File

@@ -111,6 +111,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
enableRefsLink = params("enableRefsLink").toBoolean,
enableLineBreaks = params("enableLineBreaks").toBoolean,
enableTaskList = params("enableTaskList").toBoolean,
enableAnchor = false,
hasWritePermission = hasWritePermission(repository.owner, repository.name, context.loginAccount)
)
})

View File

@@ -39,22 +39,28 @@ object Markdown {
} else markdown
// escape task list
val source = if(enableTaskList){
escapeTaskList(s)
} else s
val source = if(enableTaskList) escapeTaskList(s) else s
val options = new Options()
options.setSanitize(true)
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)
}
/**
* Extends markedj Renderer for GitBucket
*/
class GitBucketMarkedRenderer(options: Options, repository: RepositoryService.RepositoryInfo,
enableWikiLink: Boolean, enableRefsLink: Boolean, enableAnchor: Boolean, enableTaskList: Boolean, hasWritePermission: Boolean,
class GitBucketMarkedRenderer(options: Options,
repository: RepositoryService.RepositoryInfo,
enableWikiLink: Boolean,
enableRefsLink: Boolean,
enableAnchor: Boolean,
enableTaskList: Boolean,
hasWritePermission: Boolean,
pages: List[String])
(implicit val context: Context) extends Renderer(options) with LinkConverter with RequestCache {
@@ -62,11 +68,14 @@ object Markdown {
val id = generateAnchorName(text)
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){
out.append(" class=\"markdown-head\">")
out.append("<a class=\"markdown-anchor-link\" href=\"#" + id + "\"></a>")
out.append("<a class=\"markdown-anchor\" name=\"" + id + "\"></a>")
} else {
out.append(">")
}
out.append(text)
@@ -83,22 +92,21 @@ object Markdown {
var listType: String = null
if (ordered) {
listType = "ol"
}
else {
} else {
listType = "ul"
}
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 {
return "<" + listType + ">\n" + body + "</" + listType + ">\n"
"<" + listType + ">\n" + body + "</" + listType + ">\n"
}
}
override def listitem(text: String): String = {
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 {
return "<li>" + text + "</li>\n"
"<li>" + text + "</li>\n"
}
}

View File

@@ -89,6 +89,7 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
enableWikiLink: Boolean,
enableRefsLink: Boolean,
enableLineBreaks: Boolean,
enableAnchor: Boolean = true,
enableTaskList: Boolean = false,
hasWritePermission: Boolean = false,
pages: List[String] = Nil)(implicit context: Context): Html =
@@ -97,7 +98,7 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
repository = repository,
enableWikiLink = enableWikiLink,
enableRefsLink = enableRefsLink,
enableAnchor = true,
enableAnchor = enableAnchor,
enableLineBreaks = enableLineBreaks,
enableTaskList = enableTaskList,
hasWritePermission = hasWritePermission,

View File

@@ -1718,28 +1718,34 @@ div.markdown-body h1 {
border-bottom: 1px solid #ddd;
font-size: 2.5em;
font-weight: bold;
line-height: 1.7;
}
div.markdown-body h2 {
border-bottom: 1px solid #eee;
font-size: 2em;
line-height: 1.7;
}
div.markdown-body h3 {
font-size: 1.5em;
line-height: 1.7;
}
div.markdown-body h4 {
font-size: 1.2em;
line-height: 1.7;
}
div.markdown-body h5 {
font-size: 1em;
line-height: 1.7;
}
div.markdown-body h6 {
color:#777;
font-size: 1em;
line-height: 1.7;
}
div.markdown-body li {
@@ -1905,7 +1911,6 @@ div.markdown-body table colgroup + tbody tr:first-child td:last-child {
.markdown-head {
position: relative;
line-height: 1.7;
}
a.markdown-anchor-link {