mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
fix(lists): Fix makeMarkdown tasklist (#846)
Fix makeMarkdown() with tasklist by adding input subparser. Close #774 Co-authored-by: Estevão Soares dos Santos <estevao.santos@gmail.com>
This commit is contained in:
parent
cb2e4853b7
commit
626f661e8e
BIN
dist/showdown.js
vendored
BIN
dist/showdown.js
vendored
Binary file not shown.
BIN
dist/showdown.js.map
vendored
BIN
dist/showdown.js.map
vendored
Binary file not shown.
BIN
dist/showdown.min.js
vendored
BIN
dist/showdown.min.js
vendored
Binary file not shown.
BIN
dist/showdown.min.js.map
vendored
BIN
dist/showdown.min.js.map
vendored
Binary file not shown.
16
src/subParsers/makemarkdown/input.js
Normal file
16
src/subParsers/makemarkdown/input.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
showdown.subParser('makeMarkdown.input', function (node, globals) {
|
||||
'use strict';
|
||||
|
||||
var txt = '';
|
||||
if (node.getAttribute('checked') !== null) {
|
||||
txt += '[x]';
|
||||
} else {
|
||||
txt += '[ ]';
|
||||
}
|
||||
var children = node.childNodes,
|
||||
childrenLength = children.length;
|
||||
for (var i = 0; i < childrenLength; ++i) {
|
||||
txt += showdown.subParser('makeMarkdown.node')(children[i], globals);
|
||||
}
|
||||
return txt;
|
||||
});
|
|
@ -113,6 +113,10 @@ showdown.subParser('makeMarkdown.node', function (node, globals, spansOnly) {
|
|||
txt = showdown.subParser('makeMarkdown.break')(node, globals);
|
||||
break;
|
||||
|
||||
case 'input':
|
||||
txt = showdown.subParser('makeMarkdown.input')(node, globals);
|
||||
break;
|
||||
|
||||
default:
|
||||
txt = node.outerHTML + '\n\n';
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<h1 id="mythings">my things</h1>
|
||||
<ul>
|
||||
<li>foo</li>
|
||||
<li class="task-list-item" style="list-style-type: none;"><input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;"> bar</li>
|
||||
<li class="task-list-item" style="list-style-type: none;"><input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;"> baz</li>
|
||||
<li class="task-list-item" style="list-style-type: none;"><input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;" checked> bazinga</li>
|
||||
</ul>
|
||||
<p>otherthings</p>
|
8
test/functional/makemarkdown/cases/features/tasklists.md
Normal file
8
test/functional/makemarkdown/cases/features/tasklists.md
Normal file
|
@ -0,0 +1,8 @@
|
|||
# my things
|
||||
|
||||
- foo
|
||||
- [ ] bar
|
||||
- [ ] baz
|
||||
- [x] bazinga
|
||||
|
||||
otherthings
|
23
test/functional/makemarkdown/testsuite.features.js
Normal file
23
test/functional/makemarkdown/testsuite.features.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
/**
|
||||
* Created by Estevao on 08-06-2015.
|
||||
*/
|
||||
var bootstrap = require('./makemarkdown.bootstrap.js'),
|
||||
showdown = bootstrap.showdown,
|
||||
assertion = bootstrap.assertion,
|
||||
testsuite = bootstrap.getTestSuite('test/functional/makemarkdown/cases/features/');
|
||||
|
||||
describe('makeMarkdown() features testsuite', function () {
|
||||
'use strict';
|
||||
|
||||
describe('issues', function () {
|
||||
for (var i = 0; i < testsuite.length; ++i) {
|
||||
var converter;
|
||||
if (testsuite[i].name === '#164.4.tasklists') {
|
||||
converter = new showdown.Converter({tasklists: true});
|
||||
} else {
|
||||
converter = new showdown.Converter();
|
||||
}
|
||||
it(testsuite[i].name.replace(/-/g, ' '), assertion(testsuite[i], converter));
|
||||
}
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user