mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 22:15:51 +01:00
Fix Markdown testcase
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package gitbucket.core.view
|
||||
|
||||
import java.text.Normalizer
|
||||
import java.util.regex.Pattern
|
||||
import java.util.{Optional, Locale}
|
||||
|
||||
import gitbucket.core.controller.Context
|
||||
@@ -19,7 +20,7 @@ object Markdown {
|
||||
* @param enableRefsLink if true then issue reference (e.g. #123) is rendered as link
|
||||
* @param enableAnchor if true then anchor for headline is generated
|
||||
* @param enableTaskList if true then task list syntax is available
|
||||
* @param hasWritePermission
|
||||
* @param hasWritePermission true if user has writable to ths given repository
|
||||
* @param pages the list of existing Wiki pages
|
||||
*/
|
||||
def toHtml(markdown: String,
|
||||
@@ -37,8 +38,7 @@ object Markdown {
|
||||
|
||||
// escape task list
|
||||
val source = if(enableTaskList){
|
||||
s.replaceAll("""(?m)^( *)- \[([x| ])\] """, "$1* task:$2: ")
|
||||
// escapeTaskList(s)
|
||||
escapeTaskList(s)
|
||||
} else s
|
||||
|
||||
val options = new Options()
|
||||
@@ -46,12 +46,9 @@ object Markdown {
|
||||
Marked.marked(source, options, renderer)
|
||||
}
|
||||
|
||||
// private def escapeTaskList(text: String): String = {
|
||||
// Pattern.compile("""^( *)- \[([x| ])\] """, Pattern.MULTILINE).matcher(text).replaceAll("$1* task:$2: ")
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Extends markedj Renderer for GitBucket
|
||||
*/
|
||||
class GitBucketMarkedRenderer(options: Options, repository: RepositoryService.RepositoryInfo,
|
||||
enableWikiLink: Boolean, enableRefsLink: Boolean, enableAnchor: Boolean, enableTaskList: Boolean, hasWritePermission: Boolean,
|
||||
pages: List[String])
|
||||
@@ -163,16 +160,23 @@ class GitBucketMarkedRenderer(options: Options, repository: RepositoryService.Re
|
||||
}
|
||||
}
|
||||
|
||||
private def generateAnchorName(text: String): String = {
|
||||
}
|
||||
|
||||
def escapeTaskList(text: String): String = {
|
||||
Pattern.compile("""^( *)- \[([x| ])\] """, Pattern.MULTILINE).matcher(text).replaceAll("$1* task:$2: ")
|
||||
}
|
||||
|
||||
def generateAnchorName(text: String): String = {
|
||||
val normalized = Normalizer.normalize(text.replaceAll("<.*>", "").replaceAll("[\\s]", "-"), Normalizer.Form.NFD)
|
||||
val encoded = StringUtil.urlEncode(normalized)
|
||||
encoded.toLowerCase(Locale.ENGLISH)
|
||||
}
|
||||
|
||||
private def convertCheckBox(text: String, hasWritePermission: Boolean): String = {
|
||||
def convertCheckBox(text: String, hasWritePermission: Boolean): String = {
|
||||
val disabled = if (hasWritePermission) "" else "disabled"
|
||||
text.replaceAll("task:x:", """<input type="checkbox" class="task-list-item-checkbox" checked="checked" """ + disabled + "/>")
|
||||
.replaceAll("task: :", """<input type="checkbox" class="task-list-item-checkbox" """ + disabled + "/>")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ package gitbucket.core.view
|
||||
|
||||
import org.specs2.mutable._
|
||||
|
||||
class GitBucketHtmlSerializerSpec extends Specification {
|
||||
class MarkdownSpec extends Specification {
|
||||
|
||||
import GitBucketHtmlSerializer._
|
||||
import Markdown._
|
||||
|
||||
"generateAnchorName" should {
|
||||
"convert whitespace characters to hyphens" in {
|
||||
Reference in New Issue
Block a user