linsir / markdown-it-task-checkbox Goto Github PK
View Code? Open in Web Editor NEWA markdown-it plugin to create GitHub-style task lists with checkbox
License: Other
A markdown-it plugin to create GitHub-style task lists with checkbox
License: Other
The package is named "markdown-it-task-checkbox" but the title of README is
markdown-it-task-lists
If either the space between [ and ], or the space after ] is a non-breaking space (ascii code 160), then it will not render the check-list correctly.
The reason for this issue, is that we have many people making content in markdown for our project, and some of them (probably using a Mac) inadvertently inserted non-breaking spaces (alt+space), and thus ended up with strange lists.
If the owner (@linsir) agrees that non-breaking spaces should be allowed, I can make a PR that allows for non-breaking spaces. If not, please just close this issue.
There's no means of creating an incomplete/indeterminate checkbox.
Because indeterminate can't be generated with straight html, it might not be feasible.
Documentation around Indeterminate Checkboxes
Ideally, the Markdown side might be represented as [-]
, then after the HTML is rendered, using JS for post-processing into indeterminate.
The parser seems to include the space that occurs immediately after the checkbox into the label.
When I try the example from the README, md.render('- [x] unchecked')
,
...<label for="cbx_0"> unchecked</label>...
(note the space before unchecked
)...<label for="cbx_0">unchecked</label>...
(no space)So, the output is slightly different from what the README shows.
Intuitively, it also does not make sense to include the space, since it is just part of the syntax to separate the checkbox from the actual label content (even the startsWithTodoMarkdown()
regards this space as part of the required syntax) .
I tried using this plugin in combination with prosemirror-markdown which only uses markdown-it
to parse the text but not to render HTML. It turns out the space is already present in the tokens generated by markdown-it-task-checkbox
.
Concretely, I could track the problem down to slice(3);
in line 63, which just removes the first 3 characters, i.e. [x]
. Changing this to slice(4);
fixes the problem for me.
When using the xhtmlOut flag and the markdown-it-task-list plugin with the wrapper div option, the wrapper div is self-closed by markdown-it, so it no longer wraps the input and label, but the div's end tag is left as well, so the markup is invalid XHTML:
import MarkdownIt from "markdown-it"
import MarkdownItTaskCheckbox from "markdown-it-task-checkbox"
const xhtmlParser = MarkdownIt({
html: true,
xhtmlOut: true,
}).use(MarkdownItTaskCheckbox , { divWrap: true });
var html = xhtmlParser.render("- [ ] unchecked item 1");
console.log(html);
<ul class="task-list">
<li class="task-list-item">
<div class="checkbox" />
<input type="checkbox" id="cbx_0" disabled="true" />
<label for="cbx_0"> unchecked item 1</label>
</div>
</li>
</ul>
The MarkdownIt author quickly claimed that this is an issue with the plugin, not MarkdownIt. I'm not sure either way, as I'm not familiar enough with the plug-in API to know if your code below is calling MarkdownIt in some way that would result in this issue during XHTML output:
markdown-it-task-checkbox/index.js
Line 69 in 6c684bb
Reference to the MarkdownIt issue:
There are especially case of missing underscore
in package dependencies for lodash
capability or not? If it is, there is no issue because I use lodash
and maked alias and dependency misssing is helpful for me.
package.json
says ISC. LICENSE file says MIT.
Hi, @linsir! Thanks for making this fork. I've been looking around, and it looks like this is the best one for my task. However I did notice that revin's original copyright isn't included in your fork anywhere, though that's part of the original license: https://github.com/revin/markdown-it-task-lists/blob/master/LICENSE
It's probably not a big deal, I've just got to be aware of the possible legal considerations for my company.
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.