Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port todo list support from marked #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ function Renderer() {

require('util').inherits(Renderer, kramedRenderer);

// Support To-Do List
Renderer.prototype.listitem = function(text) {
if (/^\s*\[[x ]\]\s*/.test(text)) {
text = text.replace(/^\s*\[ \]\s*/, '<input type="checkbox"></input> ').replace(/^\s*\[x\]\s*/, '<input type="checkbox" checked></input> ');
return '<li style="list-style: none">' + text + '</li>\n';
} else {
return '<li>' + text + '</li>\n';
}
};

// Add id attribute to headings
Renderer.prototype.heading = function(text, level) {
var id = anchorId(stripHTML(text));
Expand Down
25 changes: 25 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,28 @@ describe('Kramed renderer', function() {
result.should.eql('<h1 id="中文"><a href="#中文" class="headerlink" title="中文"></a>中文</h1>');
});
});

it('to-do list testing', function() {
var body = [
'- [ ] test unchecked',
'- [x] test checked',
'- normal list [x] [ ]',
'',
'normal text [x] [ ]',
'',
'[x] [ ] normal text'
].join('\n');

var result = r({text: body});

result.should.eql([
'<ul>',
'<li style="list-style: none"><input type="checkbox"></input> test unchecked</li>',
'<li style="list-style: none"><input type="checkbox" checked></input> test checked</li>',
'<li>normal list [x] [ ]</li>',
'</ul>',
'<p>normal text [x] [ ]</p>',
'<p>[x] [ ] normal text</p>'
].join('\n') + '\n');
});