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:
cjwind 2022-02-24 08:16:31 +08:00 committed by GitHub
parent cb2e4853b7
commit 626f661e8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 59 additions and 0 deletions

BIN
dist/showdown.js vendored

Binary file not shown.

BIN
dist/showdown.js.map vendored

Binary file not shown.

BIN
dist/showdown.min.js vendored

Binary file not shown.

Binary file not shown.

View 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;
});

View File

@ -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';
}

View File

@ -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>

View File

@ -0,0 +1,8 @@
# my things
- foo
- [ ] bar
- [ ] baz
- [x] bazinga
otherthings

View 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));
}
});
});