Permalink
Browse files

feat: Task Lists in markdown | 复选框支持

  • Loading branch information...
MOxFIVE committed Apr 26, 2016
1 parent 3c02de2 commit 3d4ddb74250d72f47876364b0e467a05b65ce8a6
Showing with 36 additions and 0 deletions.
  1. +6 −0 source/css/_partial/article.styl
  2. +30 −0 source/js/main.js
@@ -186,6 +186,12 @@
}
}
}
li.task-list {
list-style: none;
&::before{
display: none;
}
}
h1{
margin-top: 30px;
}
View
@@ -169,4 +169,34 @@ require([], function (){
});
}
// Task lists in markdown
$('ul > li').each(function() {
var taskList = {
field: $(this).text().substring(0, 2),
check: function(str) {
var re = new RegExp(str);
return this.field.match(re);
}
}
var string = ["[ ]", ["[x]", "checked"]];
var checked = taskList.check(string[1][0]);
var unchecked = taskList.check(string[0]);
var $current = $(this);
function add(str, check) {
$current.html($current.html().replace(str, ""));
// In order html > prepend
$current.prepend("<input type='checkbox'" + check + ">");
}
if (checked || unchecked) {
$(this).addClass('task-list');
if (checked) {
add(string[1][0], string[1][1]);
} else {
add(string[0], "");
}
}
})
});

0 comments on commit 3d4ddb7

Please sign in to comment.