Skip to content

Commit

Permalink
feat: Task Lists in markdown | 复选框支持
Browse files Browse the repository at this point in the history
  • Loading branch information
MOxFIVE committed Apr 26, 2016
1 parent 3c02de2 commit 3d4ddb7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions source/css/_partial/article.styl
Expand Up @@ -186,6 +186,12 @@
}
}
}
li.task-list {
list-style: none;
&::before{
display: none;
}
}
h1{
margin-top: 30px;
}
Expand Down
30 changes: 30 additions & 0 deletions source/js/main.js
Expand Up @@ -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.