Skip to content

Commit 36a0914

Browse files
committed
Add browserified build process and output files
1 parent 73c75bc commit 36a0914

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ var parser = md().use(taskLists);
3333

3434
var result = parser.render(...); // markdown string containing task list items
3535
```
36+
### Browser Usage
37+
38+
If you use one of the versions of this module available in `dist/` directly in
39+
a browser by including it with a `<script>` element, it will be available
40+
globally in `window.markdownitTaskLists`.
3641

3742
## Tests
3843

dist/markdown-it-task-lists.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*! markdown-it-task-lists 1.1.0 https://github.com/revin/markdown-it-task-lists#readme by @license ISC */
2+
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.markdownitTaskLists = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
3+
// Markdown-it plugin to render GitHub-style task lists; see
4+
//
5+
// https://github.com/blog/1375-task-lists-in-gfm-issues-pulls-comments
6+
// https://github.com/blog/1825-task-lists-in-all-markdown-documents
7+
8+
module.exports = function(md, options) {
9+
md.core.ruler.after('inline', 'github-task-lists', function(state) {
10+
var tokens = state.tokens;
11+
for (var i = 2; i < tokens.length; i++) {
12+
if (isTodoItem(tokens, i)) {
13+
todoify(tokens[i], state.Token);
14+
tokens[i-2].attrSet('class', 'task-list-item');
15+
tokens[parentToken(tokens, i-2)].attrSet('class', 'task-list');
16+
}
17+
}
18+
});
19+
};
20+
21+
function parentToken(tokens, index) {
22+
var targetLevel = tokens[index].level - 1;
23+
for (var i = index - 1; i >= 0; i--) {
24+
if (tokens[i].level === targetLevel) {
25+
return i;
26+
}
27+
}
28+
return -1;
29+
}
30+
31+
function isTodoItem(tokens, index) {
32+
return isInline(tokens[index]) &&
33+
isParagraph(tokens[index - 1]) &&
34+
isListItem(tokens[index - 2]) &&
35+
startsWithTodoMarkdown(tokens[index]);
36+
}
37+
38+
function todoify(token, TokenConstructor) {
39+
token.children.unshift(makeCheckbox(token, TokenConstructor));
40+
token.children[1].content = token.children[1].content.slice(3);
41+
token.content = token.content.slice(3);
42+
}
43+
44+
function makeCheckbox(token, TokenConstructor) {
45+
var checkbox = new TokenConstructor('html_inline', '', 0);
46+
if (token.content.indexOf('[ ]') === 0) {
47+
checkbox.content = '<input class="task-list-item-checkbox" disabled="" type="checkbox">';
48+
} else if (token.content.indexOf('[x]') === 0) {
49+
checkbox.content = '<input class="task-list-item-checkbox" checked="" disabled="" type="checkbox">';
50+
}
51+
return checkbox;
52+
}
53+
54+
function isInline(token) { return token.type === 'inline'; }
55+
function isParagraph(token) { return token.type === 'paragraph_open'; }
56+
function isListItem(token) { return token.type === 'list_item_open'; }
57+
58+
function startsWithTodoMarkdown(token) {
59+
// leading whitespace in a list item is already trimmed off by markdown-it
60+
return token.content.indexOf('[ ]') === 0 || token.content.indexOf('[x]') === 0;
61+
}
62+
63+
},{}]},{},[1])(1)
64+
});

dist/markdown-it-task-lists.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@
44
"description": "A markdown-it plugin to create GitHub-style task lists",
55
"main": "index.js",
66
"scripts": {
7-
"test": "mocha --timeout 5000"
7+
"test": "mocha --timeout 5000",
8+
"clean": "rm -Rf dist && mkdir dist",
9+
"build": "npm run clean && npm run build-dist",
10+
"build-dist": "npm run build-dist-copyright && npm run build-dist-file && npm run build-dist-min",
11+
"build-dist-copyright": "echo /*! ${npm_package_name} ${npm_package_version} ${npm_package_homepage} by ${npm_package_author} @license ${npm_package_license} \\*/ > dist/${npm_package_name}.js",
12+
"build-dist-file": "browserify ${npm_package_main} -s markdownitTaskLists >> dist/${npm_package_name}.js",
13+
"build-dist-min": "uglifyjs dist/${npm_package_name}.js -b beautify=false,ascii-only=true -c -m --preamble \"/*! ${npm_package_name} ${npm_package_version} ${npm_package_homepage} by ${npm_package_author} @license {$npm_package_license} */\" > dist/${npm_package_name}.min.js"
814
},
915
"repository": {
1016
"type": "git",
1117
"url": "git@github.com:revin/markdown-it-task-lists.git"
1218
},
1319
"dependencies": {},
1420
"devDependencies": {
21+
"browserify": "*",
1522
"cheerio": "^0.20.0",
1623
"markdown-it": "^6.0.0",
17-
"mocha": "^2.4.5"
24+
"mocha": "*",
25+
"uglify": "*"
1826
},
1927
"keywords": [
2028
"markdown",

0 commit comments

Comments
 (0)