mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 14:05:52 +01:00
Add nested task list support
This commit is contained in:
@@ -157,6 +157,28 @@ class GitBucketHtmlSerializer(
|
|||||||
printWithAbbreviations(text)
|
printWithAbbreviations(text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override def visit(node: BulletListNode): Unit = {
|
||||||
|
if (printChildrenToString(node).contains("""class="task-list-item-checkbox" """)) {
|
||||||
|
printer.println().print("""<ul class="task-list">""").indent(+2)
|
||||||
|
visitChildren(node)
|
||||||
|
printer.indent(-2).println().print("</ul>")
|
||||||
|
} else {
|
||||||
|
printIndentedTag(node, "ul")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override def visit(node: ListItemNode): Unit = {
|
||||||
|
if (printChildrenToString(node).contains("""class="task-list-item-checkbox" """)) {
|
||||||
|
printer.println()
|
||||||
|
printer.print("""<li class="task-list-item">""")
|
||||||
|
visitChildren(node)
|
||||||
|
printer.print("</li>")
|
||||||
|
} else {
|
||||||
|
printer.println()
|
||||||
|
printTag(node, "li")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object GitBucketHtmlSerializer {
|
object GitBucketHtmlSerializer {
|
||||||
@@ -171,12 +193,12 @@ object GitBucketHtmlSerializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def escapeTaskList(text: String): String = {
|
def escapeTaskList(text: String): String = {
|
||||||
Pattern.compile("""^ *- \[([x| ])\] """, Pattern.MULTILINE).matcher(text).replaceAll("task:$1: ")
|
Pattern.compile("""^( *)- \[([x| ])\] """, Pattern.MULTILINE).matcher(text).replaceAll("$1* task:$2: ")
|
||||||
}
|
}
|
||||||
|
|
||||||
def convertCheckBox(text: String, hasWritePermission: Boolean): String = {
|
def convertCheckBox(text: String, hasWritePermission: Boolean): String = {
|
||||||
val disabled = if (hasWritePermission) "" else "disabled"
|
val disabled = if (hasWritePermission) "" else "disabled"
|
||||||
text.replaceAll("task:x:", """<input type="checkbox" checked="checked" """ + disabled + "/>")
|
text.replaceAll("task:x:", """<input type="checkbox" class="task-list-item-checkbox" checked="checked" """ + disabled + "/>")
|
||||||
.replaceAll("task: :", """<input type="checkbox" """ + disabled + "/>")
|
.replaceAll("task: :", """<input type="checkbox" class="task-list-item-checkbox" """ + disabled + "/>")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -814,6 +814,20 @@ div.attachable div.clickable {
|
|||||||
background-color: white;
|
background-color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ul.task-list {
|
||||||
|
padding-left: 2em;
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
li.task-list-item {
|
||||||
|
list-style-type: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
li.task-list-item input.task-list-item-checkbox {
|
||||||
|
margin: 0 4px 0.25em -20px;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
/* Pull Request */
|
/* Pull Request */
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
|
|||||||
@@ -27,28 +27,28 @@ class GitBucketHtmlSerializerSpec extends Specification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
"escapeTaskList" should {
|
"escapeTaskList" should {
|
||||||
"convert '- [ ] ' to 'task: :'" in {
|
"convert '- [ ] ' to '* task: :'" in {
|
||||||
val before = "- [ ] aaaa"
|
val before = "- [ ] aaaa"
|
||||||
val after = escapeTaskList(before)
|
val after = escapeTaskList(before)
|
||||||
after mustEqual "task: : aaaa"
|
after mustEqual "* task: : aaaa"
|
||||||
}
|
}
|
||||||
|
|
||||||
"convert ' - [ ] ' to 'task: :'" in {
|
"convert ' - [ ] ' to ' * task: :'" in {
|
||||||
val before = " - [ ] aaaa"
|
val before = " - [ ] aaaa"
|
||||||
val after = escapeTaskList(before)
|
val after = escapeTaskList(before)
|
||||||
after mustEqual "task: : aaaa"
|
after mustEqual " * task: : aaaa"
|
||||||
}
|
}
|
||||||
|
|
||||||
"convert only first '- [ ] '" in {
|
"convert only first '- [ ] '" in {
|
||||||
val before = " - [ ] aaaa - [ ] bbb"
|
val before = " - [ ] aaaa - [ ] bbb"
|
||||||
val after = escapeTaskList(before)
|
val after = escapeTaskList(before)
|
||||||
after mustEqual "task: : aaaa - [ ] bbb"
|
after mustEqual " * task: : aaaa - [ ] bbb"
|
||||||
}
|
}
|
||||||
|
|
||||||
"convert '- [x] ' to 'task: :'" in {
|
"convert '- [x] ' to '* task:x:'" in {
|
||||||
val before = " - [x] aaaa"
|
val before = " - [x] aaaa"
|
||||||
val after = escapeTaskList(before)
|
val after = escapeTaskList(before)
|
||||||
after mustEqual "task:x: aaaa"
|
after mustEqual " * task:x: aaaa"
|
||||||
}
|
}
|
||||||
|
|
||||||
"convert multi lines" in {
|
"convert multi lines" in {
|
||||||
@@ -60,8 +60,8 @@ tasks
|
|||||||
val after = escapeTaskList(before)
|
val after = escapeTaskList(before)
|
||||||
after mustEqual """
|
after mustEqual """
|
||||||
tasks
|
tasks
|
||||||
task:x: aaaa
|
* task:x: aaaa
|
||||||
task: : bbb
|
* task: : bbb
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user