Add nested task list support

This commit is contained in:
bati11
2014-09-20 10:57:33 +09:00
parent e1f310317d
commit 26b14ded58
3 changed files with 48 additions and 12 deletions

View File

@@ -157,6 +157,28 @@ class GitBucketHtmlSerializer(
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 {
@@ -171,12 +193,12 @@ object GitBucketHtmlSerializer {
}
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 = {
val disabled = if (hasWritePermission) "" else "disabled"
text.replaceAll("task:x:", """<input type="checkbox" checked="checked" """ + disabled + "/>")
.replaceAll("task: :", """<input type="checkbox" """ + 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 + "/>")
}
}

View File

@@ -814,6 +814,20 @@ div.attachable div.clickable {
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 */
/****************************************************************************/

View File

@@ -27,28 +27,28 @@ class GitBucketHtmlSerializerSpec extends Specification {
}
"escapeTaskList" should {
"convert '- [ ] ' to 'task: :'" in {
"convert '- [ ] ' to '* task: :'" in {
val before = "- [ ] aaaa"
val after = escapeTaskList(before)
after mustEqual "task: : aaaa"
after mustEqual "* task: : aaaa"
}
"convert ' - [ ] ' to 'task: :'" in {
"convert ' - [ ] ' to ' * task: :'" in {
val before = " - [ ] aaaa"
val after = escapeTaskList(before)
after mustEqual "task: : aaaa"
after mustEqual " * task: : aaaa"
}
"convert only first '- [ ] '" in {
val before = " - [ ] aaaa - [ ] bbb"
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 after = escapeTaskList(before)
after mustEqual "task:x: aaaa"
after mustEqual " * task:x: aaaa"
}
"convert multi lines" in {
@@ -60,8 +60,8 @@ tasks
val after = escapeTaskList(before)
after mustEqual """
tasks
task:x: aaaa
task: : bbb
* task:x: aaaa
* task: : bbb
"""
}